iOS开发之边缘手势返回(解决自定义返回按钮手势无效)

来源:互联网 发布:php转换大小写 编辑:程序博客网 时间:2024/05/29 18:26
如果没记错,从iOS7开始加入了屏幕边缘返回手势(无需设置),但是如果自定义返回按钮的话则失效,这时候就需要下面的方法:

因为我是系统分级的项目,所以就直接写在了UITabBarController中:

AppDelegate中:
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];    self.window.backgroundColor = [UIColor whiteColor];    TCTabBarController *tabbarVc = [[TCTabBarController alloc]init];    self.window.rootViewController = tabbarVc;
TCTabBarController中:
    TCNavigationController *nav = [[TCNavigationController alloc]initWithRootViewController:childVc]; **在这里加上下面两句**       childVc.navigationController.interactivePopGestureRecognizer.enabled = YES;    childVc.navigationController.interactivePopGestureRecognizer.delegate = self;//遵守UIGestureRecognizerDelegate    [self addChildViewController:nav];
实现代理方法
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{  return YES;}

搞定!

0 0