iOS 上下左右手势识别
- (void)viewDidLoad {
//建立滑动手势
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];
//设置滑动方向,下面以此类推
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
[super viewDidLoad];
}
//这个是协议回调,所以需要遵循 UIGestureRecognizerDelegate协议
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe received."); www.zzzyk.com
if (recognizer.direction==UISwipeGestureRecognizerDirectionDown) {
NSLog(@"向下滑动");
//执行程序
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionUp) {
NSLog(@"向上滑动");
//执行程序
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"向左滑动");
//执行程序
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
NSLog(@"向右滑动");
//执行程序
}
}
补充:移动开发 , IOS ,