我有一个基本视图控制器,我的所有viewcontrollers都继承它。
@interface BaseViewController () <UIGestureRecognizerDelegate>
@end
@implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tabBarController.tabBar.translucent = NO;
self.navigationController.navigationBar.translucent = NO;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
self.navigationItem.backBarButtonItem.title = @"";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
- (void) popToPreViewController {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - getter and setter
- (UIButton *) backButton {
if (!_backButton) {
_backButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 20.0, 20.0)];
[_backButton addTarget:self action:@selector(popToPreViewController) forControlEvents:UIControlEventTouchUpInside];
[_backButton setImage:[UIImage imageNamed:@"main_back"] forState:UIControlStateNormal];
_backButton.hidden = YES;
}
return _backButton;
}
@end
有时推送到另一个视图控制器会卡住,但应用程序不会崩溃。按主页按钮再次打开应用程序,它显示另一个视图控制器。这个baseviewcontroller有什么问题吗?
答案 0 :(得分:0)
我很长一段时间一直困扰这个问题,现在找到解决方案。 该问题的原因是根控制器执行手势弹出操作,发生上述问题。解决方法是禁用根控制器上的手势弹出并在非根控制器上打开手势弹出窗口。
/// The controller is fully displayed, opening the gesture pop
Func navigationController (_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
If viewControllers.first == viewController {
InteractivePopGestureRecognizer? .isEnabled = false
} Else {
InteractivePopGestureRecognizer? .isEnabled = true
}
NavigationBar.sendSubview (toBack: navigationBar.overlay)
}