+[CATransaction synchronize] called within transaction

我们两清 提交于 2019-11-27 17:09:08

问题


If I close my iPad app while I'm loading data from services, the app closes but then immediately opens again without my doing anything. At this point, I am not able to do anything; I can't close the app and I can't interact with the app or the device. The only way to use the device again is to restart it. The app does not crash, it simply disables the device.

When this happens, the following line appears in the console three times right after applicationWillResignActive and applicationDidEnterBackground:

+[CATransaction synchronize] called within transaction

It'd be almost okay if the app crashes, but the fact that the device is rendered completely useless is a huge problem. If I could intercept this bug or somehow detect when CATransaction raises this issue, then that'd be fine.

Any ideas?


回答1:


This happens when more than one animations are taking place on main thread. I faced the same problem. In my case application freezes while animating the CALayer and rotating the device simultaneously. So I stopped the animation while rotating the device.

Look for the code

[CATransaction begin]

//foo
[CATransaction commit]

Make sure that animation inside this code does not overlap with your other animations on main thread.




回答2:


This can show up in the logs if you use UIWindow.rootViewController to skip storyboards altogether.

To ditch the log message you can remove the storyboard, remove the key associating the Storyboard with your app in info.plist, set LaunchScreen.storyboard as the Main Interface in the target and use

window = UIApplication.shared.keyWindow!

inside AppDelegate to get the main window and assign your UIViewController on it.



来源:https://stackoverflow.com/questions/7196197/catransaction-synchronize-called-within-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!