2016-03-21 12 views
0

私はベースビューコントローラを持っており、すべてのビューコントローラがそれを継承しています。iOS別のビューコントローラにプッシュするget stuck

@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 

は時々動けなくなり、別のビューコントローラをプッシュしますが、アプリはcrash.Pressホームボタンせず、再びアプリを開いて、それは別のビューコントローラが表示されます。このbaseviewcontrollerに何か問題はありますか?

+0

は「_backButton = [[UIButtonのalloc] initWithFrameバックボタンに設定されたRECT私は見ることができますが、ベース・ビュー・コントローラから子ビューコントローラを提示する方法 –

+0

一つの問題は非常に小さいフレームであることをより多くのコードを提供します0.0、0.0、20.0、20.0)]; '。適切なユーザータップを受信するには少なくとも45x45である必要があります。ボタンインセットを使用してボタン画像を配置し、フレームを45x45以上に保持 –

+0

@ aman.sood Thx! – jxdwinter

答えて

0

私は長い間この問題に悩まされていましたが、解決策が見つかりました。 この問題の原因は、ルートコントローラーがジェスチャーポップ操作を実行するためです。上記の問題が発生します。回避策は、ルートコントローラーでジェスチャーポップを無効にし、非ルートコントローラーでジェスチャーポップを開くことです。 CGRectMake(:

/// 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) 
} 
関連する問題