【发布时间】:2014-06-16 17:34:52
【问题描述】:
所以我用 pageControl 制作了一个页面(这是一个有多个视图的页面,其中的点表示您所在的页面),我的代码在viewDidLoad 中如下所示:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
UIView *temp = [[UIView alloc]initWithFrame:self.view.frame];
temp.backgroundColor = [UIColor clearColor];
[temp addGestureRecognizer:swipe];
[self.view addSubview:temp];
在 swipeAction 选择器中我有:
- (void)swipeAction: (UISwipeGestureRecognizer *)sender{
NSLog(@"Swipe action called");
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//Do Something
}
else if (sender.direction == UISwipeGestureRecognizerDirectionRight){
//Do Something Else
}
}
令我惊讶的是,此方法仅在您向右滑动时才有效(即调用 else if 块)。当您向左滑动时,swipeAction 甚至不会被调用!这很奇怪,为什么会发生这种情况,我应该如何更改我的代码?任何答复表示赞赏。非常感谢!
【问题讨论】:
-
带有此识别器的视图是否位于导航控制器中?
-
@SimonGoldeen 不,它只是一个普通的
UIView
标签: ios xcode uigesturerecognizer uiswipegesturerecognizer