码迷,mamicode.com
首页 > 移动开发 > 详细

解决iOS7自定义返回按钮后不能侧滑返回的问题

时间:2015-05-07 17:06:51      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:uinavigationcontroller   pop   侧滑返回   

    iOS7自带侧滑返回功能,但是自定义返回按钮之后,侧滑返回功能会失效,解决办法如下:

    自定义一个UINavigationController,实现几个代理方法

@interface CustomNavigationController : UINavigationController

@end
#import "CustomNavigationController.h"

@interface CustomNavigationController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate>
@property(nonatomic, weak) UIViewController *currentShowVC;
@end

@implementation CustomNavigationController

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
  CustomNavigationController *nav = [super initWithRootViewController:rootViewController];
  nav.interactivePopGestureRecognizer.delegate = self;
  nav.delegate = self;
  return nav;
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  if (1 == navigationController.viewControllers.count) {
    self.currentShowVC = nil;
  } else {
    self.currentShowVC = viewController;
  }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
  if (gestureRecognizer == self.interactivePopGestureRecognizer) {
    return (self.currentShowVC == self.topViewController);
  }
  return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
      [otherGestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
    return YES;
  } else {
    return NO;
  }
}
@end


    然后,将你的UINavigationController都替换成该自定的NavigationController就OK了

解决iOS7自定义返回按钮后不能侧滑返回的问题

标签:uinavigationcontroller   pop   侧滑返回   

原文地址:http://8386217.blog.51cto.com/8376217/1643798

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!