自定義導(dǎo)航欄返回鍵 右滑返回失效

自定義返回按鈕時(shí) 右滑返回將會(huì)失效

解決方法1

我是直接在集成的UINavigaionController里直接加一句代碼

- (void)viewDidLoad {
    [super viewDidLoad];
//遵守代理
    self.interactivePopGestureRecognizer.delegate = self;
}
解決方法1

也可以自己響應(yīng)手勢(shì)的事件

[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    return YES;
}

如上兩種方法不推薦使用,因?yàn)?,比如說(shuō)在rootViewController的時(shí)候這個(gè)手勢(shì)也可以響應(yīng),導(dǎo)致整個(gè)程序頁(yè)面不響應(yīng);如果在push的同時(shí)我觸發(fā)這個(gè)手勢(shì),那么會(huì)導(dǎo)致navigationBar錯(cuò)亂,甚至crash

解決方法3

也是在集成UINavigaionController

@interface EYNavigationController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate>

@property(nonatomic,weak) UIViewController* currentShowVC;

@end

-(id)initWithRootViewController:(UIViewController *)rootViewController {
    EYNavigationController *nvc= [super initWithRootViewController:rootViewController];
    self.interactivePopGestureRecognizer.delegate = self;
    nvc.delegate = self;
    return nvc;
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
}
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    if (navigationController.viewControllers.count == 1)
        self.currentShowVC = nil;
    else {
        self.currentShowVC = viewController;
    }
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    
    if (gestureRecognizer == self.interactivePopGestureRecognizer) {
        return (self.currentShowVC == self.topViewController);
    }
    return YES;
}
全屏返回請(qǐng)看全屏返回
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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