关于在APP中边缘滑动返回卡顿问题

本文介绍了解决iOS应用中边缘滑动返回功能与MMDrawerController左侧菜单冲突的问题。通过调整UINavigationControllerDelegate方法,禁用和启用交互式弹出手势识别器,确保滑动返回与侧边栏功能正常工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于想在项目中加入,任意界面都能够在边缘滑动返回上一级,于是使用了 UIGestureRecognizerDelegate
self.navigationController.interactivePopGestureRecognizer.delegate = self;

却引入了问题:
应用中使用了MMDrawerController实现左边侧边栏功能。在主页进入二级界面后。再返回。当多次在边缘尝试滑动打开侧边栏时可以必现bug(整个界面无法操作),当再次尝试边缘滑动时,发现从右边缘出现了上次打开的二级菜单。

解决方案:
在导航栏基类中需要遵守 UINavigationControllerDelegate

- (void)viewDidLoad {
    [super viewDidLoad];
    __weak HyBaseNavgationController *weakSelf = self;
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = weakSelf;
        self.delegate = weakSelf;
    }
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
   if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)]&&animated == YES ){
        self.interactivePopGestureRecognizer.enabled = NO;
    }
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animate {

    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){

        if (navigationController.childViewControllers.count == 1) {

            self.interactivePopGestureRecognizer.enabled = NO;

        }else
            self.interactivePopGestureRecognizer.enabled = YES;
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值