【iPhone代码片段之四】手势识别器的用法 .

swipe对应手势识别器是UISwipeGestureRecognizer,示例代码如下:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
label.text=@"";
//注册GestureRecognizer
//注册上下手势
UISwipeGestureRecognizer *vertical = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(reportVerticalSwipe:)];
vertical.direction = UISwipeGestureRecognizerDirectionUp|UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:vertical];

//注册左右手势
UISwipeGestureRecognizer *horizontal = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(reportHoriziontalSwipe:)];
horizontal.direction = UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:horizontal];
}

-(void)reportHoriziontalSwipe:(UIGestureRecognizer *)recognizer{
label.text = @"左右滑动";
[self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
}

-(void)reportVerticalSwipe:(UIGestureRecognizer *)recognizer{
label.text = @"上下滑动";
[self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
}

-(void)eraseText{
label.text = @"";
}


Tap对应UITapGestureRecognizer

Pinch对应UIPinchGestureRecognizer

使用方法与上述示例大同小异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值