Unbalanced calls to begin/end appearance transitions for <UIViewController>
2016-02-27 16:33
591 查看
http://stackoverflow.com/questions/22676938/unbalanced-calls-to-begin-end-appearance-transitions-for-uiviewcontroller
Based on the Apple
documentation I came up with the following method to switch between controllers in a containment controller. When there is an
am getting
This is how I call it:
To track this down I am logging the appearance transitions
This is what the log looks like:
Now I am a little puzzled. What's the problem here?
问题解决办法:
Turns out
adds the view.
This method adds the second view controller’s view to the view hierarchy and then performs the animations defined in your animations block. After the animation completes, it removes the first view controller’s view from the view hierarchy.
Which means the
to be adjusted accordingly.
Based on the Apple
documentation I came up with the following method to switch between controllers in a containment controller. When there is an
oldCI
am getting
Unbalanced calls to begin/end appearance transitions for <...>on the console.
- (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]; } }
This is how I call it:
- (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)]; }
To track this down I am logging the appearance transitions
-(void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated { [super beginAppearanceTransition:isAppearing animated:animated]; NSLog(@"**begin %@", self); } -(void)endAppearanceTransition { [super endAppearanceTransition]; NSLog(@"**end** %@", self); }
This is what the log looks like:
] **begin <SignInViewController: 0x10c769a20> ] **begin <SignUpViewController: 0x10c768770> ] Unbalanced calls to begin/end appearance transitions for <SignUpViewController: 0x10c768770>. ] **end** <SignUpViewController: 0x10c768770> ] **end** <SignInViewController: 0x10c769a20>
Now I am a little puzzled. What's the problem here?
问题解决办法:
Turns out
transitionFromViewController:toViewController:duration:options:animations:completion:also
adds the view.
This method adds the second view controller’s view to the view hierarchy and then performs the animations defined in your animations block. After the animation completes, it removes the first view controller’s view from the view hierarchy.
Which means the
addSubviewneeds
to be adjusted accordingly.
- (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 }; 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 { [contentView addSubview:newC.view]; oldC.view.alpha = 0.0f; newC.view.alpha = 1.0f; [oldC removeFromParentViewController]; [newC didMoveToParentViewController:self]; } }
相关文章推荐
- unbalanced calls to begin/end appearance transitions for uiviewcontroller的解决方法
- JSP学习笔记五之application和page对象
- android studio编译项目,9 patch图片报错Crunching Cruncher
- Android开发之EditText属性详解
- Android实战技巧:ViewStub的应用
- android开发习惯优化小记
- 如何判断android activity是否运行
- 最新力作:《Android自定义组件开发详解》
- Objective-C(3)对象间的has a关系---复合关系
- iOS,@property,@synthesize, nonatomic,atomic,strong,weak,copy,assign,retain解析
- 用Android Studio 运行ndk 程序
- Android继承AppCompatActivity后实现全屏设置
- Swift 笔记(八)
- 向applicationContext.xml中导入jdbc文件
- ioS开发知识(三十二)
- Android属性动画
- 【iOS开发之静态库、动态库】
- ios Apple Pay 简单使用
- android官网图像与动画章节demo的分析
- Android studio导入jar包及Library包