Xcode警告Unbalanced calls to begin/end appearance transitions for <TabBarController: 0x160806c00>.

通常iOS开发中会自定义Tab,跳转时通常会使如下代码直接跳转:

LZHTabBarController *tabVC = [[LZHTabBarController alloc]init];

[UIApplication sharedApplication].delegate.window.rootViewController = tabVC;

这个时候Xcode会警告Unbalancedcalls tobegin/endappearance transitionsfor<TabBarController:0x160806c00>.

原因就是控制器跳转时动画未结束就立马进行下一步,解决方法就是通过GCD延时让动画先结束再跳转,代码如下:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

              LZHTabBarController *tabVC = [[LZHTabBarController alloc]init];

              [UIApplication sharedApplication].delegate.window.rootViewController = tabVC;

   });

建议延时最低0.1s,保证动画能够结束,太长会影响跳转视觉效果

同时也可在自定义的Tab中添加如下代码预防问题:

-(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];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容