iOS 上下左右手势识别
来源:未知 责任编辑:责任编辑 发表时间:2013-12-01 14:19 点击:次
- (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.2cto.com
if (recognizer.direction==UISwipeGestureRecognizerDirectionDown) {
NSLog(@"向下滑动");
//执行程序
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionUp) {
NSLog(@"向上滑动");
//执行程序
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"向左滑动");
//执行程序
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
相关新闻>>
- 发表评论
-
- 最新评论 更多>>