美文网首页iOS用到的
给iOS应用增加手势右划返回

给iOS应用增加手势右划返回

作者: 浅陌 | 来源:发表于2015-01-28 14:20 被阅读873次

首先需要引用两个Delegate

UIGestureRecognizerDelegate
UINavigationControllerDelegate

然后在loadView中增加

self.navigationController.delegate = self;
if (IsiOS7Later) {
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

在viewDidDisappear中释放掉
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.navigationController.delegate = nil;
}

最后添加方法
#pragma mark - UINavigationController Delegate
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}

相关文章

网友评论

    本文标题:给iOS应用增加手势右划返回

    本文链接:https://www.haomeiwen.com/subject/aiflxttx.html