我在iPhone
上处理滑动时遇到一些麻烦,我在界面中创建了一个UISwipeGestureRecognizer
var:
UISwipeGestureRecognizer *swipeRecognizer;
并在我的控制器中:viewDidLoad
方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Horizontal swipe
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeRecognizer];
}
我处理滑动的方法是:
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(@"Swipe!");
}
当我运行我的代码并进行滑动时,我什么都没得到?我应该得到:刷卡!
感谢。
答案 0 :(得分:9)
我很惊讶不会因无法识别的选择器错误而崩溃。尝试将识别器添加到视图中而不是视图控制器中:
[self.view addGestureRecognizer:swipeRecognizer]
答案 1 :(得分:0)
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
这有用吗?
你不必为每个方向添加两个gestureRecognizer吗?