iOS-導(dǎo)航控制器全屏側(cè)滑

導(dǎo)航控制器返回,網(wǎng)上已經(jīng)有開源的FDFullscreenPopGesture,屏幕本身邊緣也可以是可以側(cè)滑返回的,如果自己想簡單的時候也可以,首要要獲取控制器的interactivePopGestureRecognizer,然后獲取手勢的delegate~
如下所示:

**2016-12-08 16:48:32.573FlyElephant[21021:320874] ****全屏手勢****:<UIScreenEdgePanGestureRecognizer: 0x7fc04d809fb0; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fc04d805730>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fc04d8097c0>)>>**
**2016-12-08 16:48:32.573 FlyElephant[21021:320874] ****全屏手勢****Target:<_UINavigationInteractiveTransition: 0x7fc04d8097c0>**
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"FlyElephant";
    [self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]];
    
    NSLog(@"全屏手勢:%@",self.navigationController.interactivePopGestureRecognizer);
    NSLog(@"全屏手勢Target:%@",self.navigationController.interactivePopGestureRecognizer.delegate);
    
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    // 創(chuàng)建全屏滑動手勢,調(diào)用系統(tǒng)自帶滑動手勢的target的action方法
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    // 給導(dǎo)航控制器的view添加全屏滑動手勢
    [self.view addGestureRecognizer:pan];
    // 禁止使用系統(tǒng)自帶的滑動手勢
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    // 根控制器不側(cè)滑返回
    if (self.childViewControllers.count == 1) {
        // 表示用戶在根控制器界面,就不需要觸發(fā)滑動手勢,
        return NO;
    }
    return YES;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容