带有interactivePopGestureRecognizer的popToViewController

时间:2014-06-08 14:18:08

标签: objective-c uigesturerecognizer

我使用以下代码

[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handlePopGesture:)];

- (void)handlePopGesture:(UIGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan)
{

 } else if (gesture.state == UIGestureRecognizerStateEnded) {
    NSArray *views = [self.navigationController viewControllers];
    [self.navigationController popToViewController:[views objectAtIndex:1] animated:YES];
}

但它没有解决如何使用interactivePopGestureRecognizer弹出视图控制器的问题?

1 个答案:

答案 0 :(得分:0)

确保您的.h文件是委托。

@interface YOURVIEWCONTROLLER : UIViewController <UIGestureRecognizerDelegate> 

在你的.m include

self.navigationController.interactivePopGestureRecognizer.delegate = self;

然后你的委托方法应该识别你的手势。