滑动手势 iPhone
我在处理 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!");
}
当我运行代码并进行滑动时,我什么也没有得到?我应该得到:刷卡!
谢谢。
I have some trouble to handle swipe on iPhone
, I create in my interface a UISwipeGestureRecognizer
var:
UISwipeGestureRecognizer *swipeRecognizer;
and in my controller : viewDidLoad
method
- (void)viewDidLoad
{
[super viewDidLoad];
// Horizontal swipe
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeRecognizer];
}
And my method to handle swipe is :
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(@"Swipe!");
}
When I run my code and do a swipe I got nothing? I'm supposed to get : Swipe!
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很惊讶它不会因无法识别的选择器错误而崩溃。尝试将识别器添加到您的视图而不是视图控制器:
I'm surprised that doesn't crash with an unrecognized selector error. Try adding the recognizer to your view instead of to your view controller:
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
这有效吗?
不是要为每个方向添加两个gestureRecognizer吗?
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
Does this work?
Don't you have to add two gestureRecognizer for each direction?