0
votes

What might cause an App to stop responding correctly to interface events? One problem that I'm facing is that my app stops doing all kinds of animations, for instance, the keyboard doesn't animate, it just appears in the screen. The rotation of the device is not animated, it just rotates without animation. UIAlertView shows and dismisses without animation.

I'm developing a high performance app that creates and deallocs several objects per sec. I try to use as little memory as possible. This problem I'm describing is not preceded a by memory warning and I'm not catching any exceptions (I log all of them).

If anyone can give me any advice, I'd really appreciate it.

Obs.: There is another thing i'm curious: in my app, when i have this problem, the uiview animations stop happening. But CALayer animations are executed normally. Is there a explanation for that?

3

3 Answers

1
votes

It sounds as if you're doing some operation that is blocking the main thread. All UI is done on the main thread, so if you're also doing some long calculation on there, this will cause the UI to stop responding. Are you doing synchronous url requests? Again, this will block the main thread.

You should move as much non-UI code to a background thread as possible... do this using either GCD or NSOperations

Take a look at Apple's Concurrency Programming Guide.

Apple's take on NSThreads...

*...moving away from threads may not be possible in all cases, performance (and the simplicity of your code) can improve dramatically in places where you do make the switch. Specifically, using dispatch queues and operation queues instead of threads has several advantages:

  • It reduces the memory penalty your application pays for storing thread stacks in the application’s memory space.
  • It eliminates the code needed to create and configure your threads.
  • It eliminates the code needed to manage and schedule work on threads.
  • It simplifies the code you have to write.

Also, see this question on NSThread vs NSOperationQueue.

0
votes

You're probably blocking the main thread by doing something long-running. Are you polling or looping somewhere in your code? If you do (which you shouldn't), make sure you do it on a background thread.

0
votes

CALayer transform updates can have a higher priority than the main thread, and thus be seen even if the main UI thread is blocked. However no UI updates will happen as long as the main thread is blocked. UI objects will be frozen for the duration you block the main thread.

If you want UI animation to be smooth, your app has to return from all main thread processing to the UI run loop frequently (maybe at least 30 times per second?).