遇到的問題:
頻繁跳轉(zhuǎn)頁面淘正,偶爾出現(xiàn)界面卡死摆马,不響應(yīng)任何手勢,點(diǎn)擊事件
原因:
在視圖Push過程中鸿吆,且Push尚未完成時(shí)觸發(fā)了Pop囤采,可能會(huì)導(dǎo)致界面卡死,不響應(yīng)任何手勢惩淳,點(diǎn)擊事件
解決方法:
重寫Push事件蕉毯,在Push過程中禁用其他操作,包括滑動(dòng)返回手勢
#import "MyNavigationViewController.h"
@interface MyNavigationViewController ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>
@property (assign, nonatomic) BOOL isSwitching;
@end
@implementation MyNavigationViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.interactivePopGestureRecognizer.delegate = self;
}
/**
* 重寫push方法
*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
self.interactivePopGestureRecognizer.enabled = NO;
if (animated) {
if (self.isSwitching) {
return; // 1. 如果是動(dòng)畫,并且正在切換恕刘,直接忽略
}
self.isSwitching = YES; // 2. 否則修改狀態(tài)
}
// 所有設(shè)置搞定后, 再push控制器
[super pushViewController:viewController animated:animated];
}
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
self.interactivePopGestureRecognizer.enabled = [self.viewControllers count] > 1 ;
self.isSwitching = NO; // 3. 還原狀態(tài)
}
@end