自定義TabBarController Push下一級Controller時 會報這樣的錯誤:Unbalanced calls to begin/end appearance transitions for <XXXViewController: 0x7fcea3730650>. 網上的一些回答,都 ...
自定義TabBarController Push下一級Controller時 會報這樣的錯誤:Unbalanced calls to begin/end appearance transitions for <XXXViewController: 0x7fcea3730650>.
網上的一些回答,都說是動畫引起的,解決方法就是,加一個BOOL型的變數,檢查是否在做動畫。
if (transiting) {
return;
}
transiting = YES;
[self transitionFromViewController:_currentVC toViewController:newVC duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
} completion:^(BOOL finished) {
transiting = NO;
}];
這樣就不會出現剛纔說的那個bug了。
但是,這並沒有解決我的問題!
所以真正的答案是
自定義了TabBarController 之後必須實現以下
-(void)viewWillAppear:(BOOL)animated
{
[self.selectedViewController beginAppearanceTransition: YES animated: animated];
}
-(void) viewDidAppear:(BOOL)animated
{
[self.selectedViewController endAppearanceTransition];
}
-(void) viewWillDisappear:(BOOL)animated
{
[self.selectedViewController beginAppearanceTransition: NO animated: animated];
}
-(void) viewDidDisappear:(BOOL)animated
{
[self.selectedViewController endAppearanceTransition];
}