手势返回控制器

来源:互联网 发布:58速运抢单软件加速器 编辑:程序博客网 时间:2024/06/14 07:59

问题出现在,如果UINavigationItem重写后,就没有手势返回了.我们需要重写手势返回

闲话不多说

1.

    if ([selfrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    }

    SecondViewController *svc = [[SecondViewControlleralloc] init];

    [self.navigationControllerpushViewController:svc animated:YES];


2. 在SecondViewController中

@interface SecondViewController ()<UIGestureRecognizerDelegate>


@end

- (void)viewDidLoad {

    [superviewDidLoad];

UIButton *btn = [[UIButtonalloc] initWithFrame:CGRectMake(0 ,0,44 ,44)];

    btn.backgroundColor = [UIColorredColor];

    [btn addTarget:selfaction:@selector(backClick)forControlEvents:UIControlEventTouchUpInside];


    UIBarButtonItem *leftItem = [[UIBarButtonItemalloc] initWithCustomView:btn];

    self.navigationItem.leftBarButtonItem = leftItem;

    


     // 重写手势返回方法

    __weaktypeof (self) weakSelf =self;

    if ([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf;

    }

}

这样就有了手势返回按钮

0 0
原创粉丝点击