根据苹果文档,我提出了以下在包容性控制器中切换控制器的方法。当有
这是我称之为的方式:
为了追踪这个问题,我正在记录外观转换。
这是日志的样子:
oldC
时,控制台会显示Unbalanced calls to begin/end appearance transitions for <...>
错误信息。请注意保留HTML标记。- (void) showController:(UIViewController*)newC withView:(UIView*)contentView animated:(BOOL)animated
{
UIViewController *oldC = self.childViewControllers.firstObject;
if (oldC == newC) {
return;
}
[oldC willMoveToParentViewController:nil];
[self addChildViewController:newC];
newC.view.frame = (CGRect){ 0, 0, contentView.frame.size };
[contentView addSubview:newC.view];
if (animated && oldC != nil) {
oldC.view.alpha = 1.0f;
newC.view.alpha = 0.0f;
[self transitionFromViewController:oldC toViewController:newC duration:0.25f options:0 animations:^{
oldC.view.alpha = 0.0f;
newC.view.alpha = 1.0f;
} completion:^(BOOL finished) {
[oldC removeFromParentViewController];
[newC didMoveToParentViewController:self];
}];
} else {
oldC.view.alpha = 0.0f;
newC.view.alpha = 1.0f;
[oldC removeFromParentViewController];
[newC didMoveToParentViewController:self];
}
}
这是我称之为的方式:
- (IBAction) buttonSignIn:(id)sender
{
[self showController:self.signInViewController withView:self.contentView animated:(sender != nil)];
}
- (IBAction) buttonSignUp:(id)sender
{
[self showController:self.signUpViewController withView:self.contentView animated:(sender != nil)];
}
为了追踪这个问题,我正在记录外观转换。
-(void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated
{
[super beginAppearanceTransition:isAppearing animated:animated];
NSLog(@"**begin %@", self);
}
-(void)endAppearanceTransition
{
[super endAppearanceTransition];
NSLog(@"**end** %@", self);
}
这是日志的样子:
] **begin <SignInViewController: 0x10c769a20>
] **begin <SignUpViewController: 0x10c768770>
] Unbalanced calls to begin/end appearance transitions for <SignUpViewController: 0x10c768770>.
] **end** <SignUpViewController: 0x10c768770>
] **end** <SignInViewController: 0x10c769a20>
现在我有点困惑。这里的问题是什么?
duration:0
是安全的:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/transitionFromViewController:toViewController:duration:options:animations:completion: - Heath Borders