Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIViewController animations stop working

My app runs fine in iOS6, but in an unspecified upcoming version of iOS that I cannot name for NDA reasons, all UIViewController transition animations stop working. New views just pop into place instantly. I am not sure if this unspecified future version of iOS is the cause, as I've seen this happen occasionally in iOS6.

Sometimes animations start working for a while and then stop shortly after, making me think it's some sort of memory warning issue, but my app is using a fairly reasonable ~125MB of RAM at most times. Can anyone offer any advice or things to investigate?

like image 523
Nick Locking Avatar asked Aug 16 '13 19:08

Nick Locking


2 Answers

The described behavior has always existed: if you do work on background threads and then call and UIKit methods then more often than not the update will be delayed in a weird way.

Because of this you should always dispatch_async onto the main queue to update the UI.

Those bugs are very hard to catch since they do not always occur predictably.

To catch them I built a method that swizzles some UIKit methods to check if they are called on the main thread. This allows you to stop on a symbolic breakpoint, whenever you have forgotten to dispatch back onto main queue.

https://github.com/Cocoanetics/DTFoundation/blob/develop/Core/Source/iOS/Debug/UIView%2BDTDebug.m

like image 108
Cocoanetics Avatar answered Nov 12 '22 03:11

Cocoanetics


A good workaround from the Apple dev forums on this issue:

Do this:

[UIView setAnimationsEnabled:YES] 

And animations start working again. I suspect that this is either a straight up iOS7 bug, or somewhere in my code an animation or UIViewController launch is happening on a background thread, causing animations to stop. Probably unrelated to the unspecified future version of iOS.

like image 41
Nick Locking Avatar answered Nov 12 '22 01:11

Nick Locking