2016-03-21 8 views
0

Bir temel görüntü denetleyicim var ve tüm görüntü denetleyicileri bunu devralır.iOS Başka bir kontrolöre bastığınızda takılma

@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 

Bazen takılıp alacak başka bir görünüm denetleyicisi itin ancak uygulama crash.Press ev düğmesi yok ve tekrar uygulamayı açmak, başka bir görünüm denetleyicisi gösterir. Bu baseviewcontroller ile yanlış bir şey mi var?

+0

nasıl görebildiğim taban görünümü kontrolörü –

+0

Bir sorunlarından çocuk görünümü denetleyicileri sunuyoruz olduğunu, daha fazla kod sağlamak _backButton = [[UIButton alloc] initWithFrame' geri düğmesi için çok küçük çerçeve rect kümesidir 0.0, 0.0, 20.0, 20.0)] '. Uygun kullanıcı musluğunu almak için en az 45x45 olmalıdır. Düğme görüntüsünü yerleştirmek ve kare 45x45 veya daha büyük bir çerçeve tutmak için düğme ekleme düğmesini kullanın –

+0

@ aman.sood Thx! – jxdwinter

cevap

0

Uzun zamandır bu sorundan dolayı sıkıntı çekiyorum, şimdi bir çözüm buluyorum. Bu sorunun nedeni, kök denetleyicinin bir hareket pop işlemi gerçekleştirmesidir, yukarıda açıklanan sorun oluşur. Çözüm, kök denetleyicideki jest pop'unu devre dışı bırakmak ve root olmayan denetleyicideki joker pop'unu açmaktır. 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) 
}