简体   繁体   中英

Block-based UIView animation goes into turbo when view is not visible

I'm using the new block-oriented UIView animation methods to create a sliding-and-fading slideshow inspired by the one that shows up on the home screen of the Flickr application. It's all working very nicely, and I'm no longer intimidated by blocks.

Where I'm using this is on a page of my app that's inside UINavigationController control. Everything's fine about it, and as far as I can tell it's working correctly.

The thing is, I left one line of NSLog output in there, and when my view that houses my slideshow is not the top view controller on the stack, that sucker puts out just tons of lines of NSLog output. That thing is running once every 8.5 seconds (when a new slide is loaded) under normal circumstances, but when it's not visible it's like 16 or so per second. It goes normal again when its viewcontroller comes back to the surface, as if nothing had happened. If I wasn't talking to myself on the console, I'd never know this was happening.

My animations are on a big loop. I don't really mind if they're churning away beneath me while I'm not paying attention. You think this is a problem? My concern is that it's eating unnecessary cycles, but it doesn't seem to have any real impact even on my testing 3G. Thoughts? Is there some universal way to pause custom UIView animations?

I would be curious to know what your metric is for determining there is no "real impact" on your device. It's not unreasonable to say that the performance feel isn't impacted. I think that's legitimate, but I would be concerned as you are as to why it's happening. Have you done any profiling to see where your processor hot spots are? It would probably be wise to do that.

There might be a better way to do what you're doing. You say that your "animations are on a big loop." I'm not sure what you mean by this, but in general you shouldn't need to use a loop at all except to add an animation to an array of layers or something like that. Can you clarify what you mean? If you update your answer with some of your animation code, we can try to help you figure out what the issue might be.

I personally wouldn't feel comfortable at all shipping an app that had that problem without getting to the bottom of it even if there was no apparent usability impact.

Best Regards.

I resolved this by adding -(void)pause and -(void)resume methods to my animation UIView subclass. On pause it sets a flag that breaks the animation loop and stashes some info about where it is in the process. On resume it undoes that flag, resets the state of the things it stashed, and goes back into the loop of animation methods. Works!

I would really like to see how your stuff works. I have the same problem with a different spin.

My game uses UIViews to move objects around the screen, and I had solved the problem of pausing a long time ago (like 6 months ago). With iOS 4, i thought it would be a simple matter of just pausing the game when the app gets put into background (basically calling pause from applicationWillResignActive in my delegate), and that worked fine. But now when i resume the app, the UIAnimations just resume without the app unpausing, so the game plays on while paused... huge problem.

But, I pause my game using the same methodology, i pause the animations by getting their info from the presentation layer, storing the info, then resume by creating another animation from that spot with the remaining time as the duration. No idea why this is not working, how did you pause and resume?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM