Unbalanced calls to begin/end appearance transitions for

Log

刚才在项目中添加了一个功能:用户在注册界面注册成功后跳回登陆界面,然后执行自动登陆,登陆成功后返回上一层,垒完代码后随即用ipod touch 5 测试了下,Xcode报了一个Log:

Unbalanced calls to begin/end appearance transitions for


分析

大概知道错在那个位置了,下面贴下代码:

RegisterViewController:

RegisterViewController

LoginViewController:

Unbalanced calls to begin/end appearance transitions for <UIViewcontroller>_第1张图片
接收通知:“kUserRegisteredSuccessfully”
Unbalanced calls to begin/end appearance transitions for <UIViewcontroller>_第2张图片
通知事件
Unbalanced calls to begin/end appearance transitions for <UIViewcontroller>_第3张图片
登陆成功后pop到上层

上面的代码逻辑大概是这样的,连续使用了两次popViewController(animated: true),还有一个bug:在iPod touch 5 上RegisterViewController不会pop回上层界面,在 iPhone 6s上没有这个情况。

Unbalanced calls to begin/end appearance transitions for <UIViewcontroller>_第4张图片

原因

1.出现Unbalanced calls to begin/end appearance transitions for UIViewcontroller这样的Log,其原因就是在容器类的UIViewController(如,UINavigationController, UITabBarController)中动画没做完,然后又开始新的动画。

2.第二个pop效果没有展示,我认为和设备的处理速度有关,如有大神知道原因请回复指导


解决

解决办法:
1⃣️让动画完后再做新的动画。
2⃣️animated改为false,就是去掉动画效果。
3⃣️。。。留给大家提出更好的解决办法

根据个人需要,我选择了后者,由登陆pop回注册界面时去掉动画效果,即animated改为false,这样两个连续的pop动作只保留一个动画效果就不会出现上面的情况了。

你可能感兴趣的:(Unbalanced calls to begin/end appearance transitions for )