ios +[CATransaction同步]在事务中调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7196197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:15:58  来源:igfitidea点击:

+[CATransaction synchronize] called within transaction

iosipadlockingcatransaction

提问by Confused

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.

如果我在从服务加载数据时关闭我的 iPad 应用程序,该应用程序会关闭,但随后会立即再次打开,而我没有做任何事情。在这一点上,我什么也做不了;我无法关闭应用程序,也无法与应用程序或设备进行交互。再次使用设备的唯一方法是重新启动它。该应用程序不会崩溃,它只是禁用设备。

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

发生这种情况时,在applicationWillResignActiveapplicationDidEnterBackground之后,控制台中会立即出现以下行 3 次

+[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 CATransactionraises this issue, then that'd be fine.

如果应用程序崩溃几乎没问题,但设备完全无用的事实是一个大问题。如果我可以拦截此错误或以某种方式检测CATransaction 何时引发此问题,那就没问题了。

Any ideas?

有任何想法吗?

回答by Harsh

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.

当主线程上发生多个动画时会发生这种情况。我遇到了同样的问题。在我的情况下,应用程序在为 CALayer 设置动画并同时旋转设备时冻结。所以我在旋转设备时停止了动画。

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.

确保此代码中的动画与主线程上的其他动画不重叠。

回答by Fabian

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

如果您使用UIWindow.rootViewController完全跳过情节提要,这可能会显示在日志中。

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

要丢弃日志消息,您可以删除情节提要,删除将情节提要与您的应用程序在 info.plist 中关联的键,设置LaunchScreen.storyboardMain Interface目标中的并使用

window = UIApplication.shared.keyWindow!

inside AppDelegateto get the main windowand assign your UIViewControlleron it.

里面AppDelegate得到主要window并分配你的UIViewController