在iOS7中,我们有一个新的"从左到右滑动"手势,这是一个非常有用的功能,但现在我有一个问题。
我使用此代码自定义UINavigationBar
中的后退按钮。
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
但是这会禁用从左到右滑动""手势,所以我使用跟随代码来保持手势。
self.navigationController.interactivePopGestureRecognizer.delegate = self
然后,我发现手势异常,如果当前的ViewController有一个tableView,当tableView滚动时,手势就不会被触发。现在手势无法轻易触发,是否有某种方法可以解决?
答案 0 :(得分:27)
此代码适用于我。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}
答案 1 :(得分:4)
将interactivePopGestureRecognizer.delegate
设置为self
只是第一步。第二步是实施
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return ![otherGestureRecognizer isKindOfClass:UIPanGestureRecognizer.class];
}
在交互式弹出窗口正在进行时,需要对平移手势识别器进行测试以阻止滚动或表格视图的垂直滚动。
答案 2 :(得分:4)
添加类控制器“UIGestureRecognizerDelegate”
在ViewDidApper中添加
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.interactivePopGestureRecognizer.delegate = self
}
=)