忽略UIViewController中的UIPanGesture

时间:2013-10-07 15:48:36

标签: ios objective-c uiviewcontroller uinavigationcontroller uipangesturerecognizer

我的UINavigationController有一个UIPanGestureRecognizer

MyNavController.m
...

menuGesture.delegate = self;
[self.view addGestureRecognizer:menuGesture];

效果很好,但我需要忽略UIPanGestureRecognizer中的topViewControllers。我试过了self.view.gestureRecognizers = nil,但它没有用。

3 个答案:

答案 0 :(得分:0)

如果您需要启用/禁用已在控制器中添加的某些手势识别器,则一种方法是通过属性公开该手势识别器,然后随意启用/禁用它:

@property(nonatomic, assign/weak) UIPanGestureRecognizer* myGestureRecognizer;

...

[(MyNavController*)myController.navigationController myGestureRecognizer].enabled = NO;

(当然,您的menuGesture会存储在myGestureRecognizer中,以实现此目的。)

答案 1 :(得分:0)

您需要订阅UIGestureRecognizerDelegate,然后确定是否应该在gestureRecognizer:shouldReceiveTouch:

中允许该手势

答案 2 :(得分:0)

尝试这样:UINavigationController有一个名为

的方法
- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer