swipe对应手势识别器是UISwipeGestureRecognizer,示例代码如下:
Tap对应UITapGestureRecognizer
Pinch对应UIPinchGestureRecognizer
使用方法与上述示例大同小异。
- (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
使用方法与上述示例大同小异。
本文介绍如何在iOS应用中实现常见的手势识别,包括上下滑动、左右滑动等,并提供了具体的示例代码。此外还介绍了tap和pinch手势的实现方法。
895

被折叠的 条评论
为什么被折叠?



