iOS,手势识别简单使用

iOS目前支持的手势识别(6种)
UITapGestureRecognizer(点按)
UIPinchGestureRecognizer(捏合,二指往內或往外拨动,平时经常用到的缩放 )
UIPanGestureRecognizer(拖动,慢速移动 )
UISwipeGestureRecognizer(轻扫,快速移动)
UIRotationGestureRecognizer(旋转 )
UILongPressGestureRecognizer(长按)
 
点按手势和慢速拖动手势简单使用
//ViewController.m文件
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UIButton *gesturesBtn;
@end

 
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.navigationItem.title=@"手势测试";
    _gesturesBtn=[[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width*0.35, self.view.frame.size.height*0.4, self.view.frame.size.width*0.3, self.view.frame.size.height*0.1)];
    [_gesturesBtn setBackgroundColor:[UIColor blueColor]];
    [_gesturesBtn.layer setCornerRadius:5.0];
    [_gesturesBtn.layer setBorderWidth:0.5];
    [_gesturesBtn setTitle:@"GesturesTest" forState:UIControlStateNormal];
    [_gesturesBtn setTintColor:[UIColor blackColor]];

    //慢速滑动
    UIPanGestureRecognizer *panLeft=[[UIPanGestureRecognizeralloc]initWithTarget:self action:@selector(panLeftAction:)];
    [self.view addGestureRecognizer:panLeft];
    

    //单击手势
    UITapGestureRecognizer *tapGes=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    //点按次数
    [tapGes setNumberOfTapsRequired:1];
    //点按手指数量
    [tapGes setNumberOfTouchesRequired:1];
    //把手势加到该按钮视图上
    [_gesturesBtn addGestureRecognizer:tapGes];

    [self.view addSubview:_gesturesBtn];

}

//慢速滑动手势响应事件
-(void)panLeftAction:(UISwipeGestureRecognizer *)sender{
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"慢滑动"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

//点按手势响应事件
-(void)tapAction:(UITapGestureRecognizer *)sender{
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"点按手势" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}
@end

 

 

转载于:https://www.cnblogs.com/douniwanxia/p/5896273.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值