[bug原因与修复] Unbalanced calls to begin/end appearance transitions for...

网上找了一圈,大部分原因还是第一种,第二种找了以前没见人提过。

这个 Bug 会在你使用了 iOS 5 的新特性去管理 UIViewController 的时候出现。

Bug 的现象是 View 变成纯白,打出 Unbalanced calls to begin/end appearance transitions for 的 Log,出现有两种原因

第一个原因:
就是 self.currentView,和你要transitionTo 的界面是一样的
说白了从自己到自己不叫Transition
代码解决就是在 [self transitionFromViewController: 这句话前面加上
    if([self.childViewControllers objectAtIndex:showSegmentNum] == self.currentViewController){
        return;
    }

——分割线——

第二个原因:
动画原因,一个动画还没执行完,第二个动画又要执行,就会出错。
拿代码来说
   
 [self transitionFromViewController:self.currentViewController
                      toViewController:[self.childViewControllers objectAtIndex:showSegmentNum]
                              duration:0.0
                               options:UIViewAnimationOptionTransitionNone
                            animations:^{
                                //动画块
                            }
                            completion:^(BOOL finished) {
                                //结束块
                            }];

代码上是这样,在你执行一次[self transitionFromViewController...]之后,一次transition结束之后会执行结束块代码。
但是如果你在执行了[self transitionFromViewController...]这个方法之后,还在结束块被调用(就是transition正式结束)之前又调用了一次[self transitionFromViewController...]这个方法,就会出现白屏打Log,
解决方法:
@implementation ...
@implementation之后加入一个
 BOOL transiting;
在[self transitionFromViewController...]之前加上
</pre></div><pre name="code" class="objc">    if(transiting){
        return;
    }
    transiting = YES;
在这个结束块的时候,置
    transiting = NO;
代码总体:
BOOL transiting;
-(void)showSegmentView:(NSUInteger)showSegmentNum
{
    if(transiting){
        return;
    }
    transiting = YES;
    [self transitionFromViewController:self.currentViewController
                      toViewController:[self.childViewControllers objectAtIndex:showSegmentNum]
                              duration:0.0
                               options:UIViewAnimationOptionTransitionNone
                            animations:^{
                                //动画快
                            }
                            completion:^(BOOL finished) {
                                //结束块
                                transiting = NO;
                            }];
    self.currentViewController = [self.childViewControllers objectAtIndex:showSegmentNum];
    self.currentViewController.view.frame = self.baseRect;
}
OVER.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值