views:

554

answers:

3

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?

A: 

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.

Matt Long
Oh yeah, I totally don't. It has no apparent impact on screen-feel, but I know something's happening underneath. I guess I was kind of hoping somebody would come along and say, you know, "No worries--UIView animations on a view that's off the screen are a cheap no-op, just let 'em churn." I'll post some code from the office on Monday.
Dan Ray
A: 

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!

Dan Ray
A: 

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?

ColdLogic
I created a BOOL ivar called "paused", and when it's YES, in the `onCompletion:^` block where I bring in the next slide, I don't do that but rather save myself the state of my two UIImageViews to a pair of ivars. Then in `-(void)resume`, I take my paused-state UIImageView ivars and rebuild my animation state, and call the next UIView animation method in the chain. Not real sure how that relates to what you're dealing with, but it's what I'm doing.
Dan Ray
Well, thats basically what i had as well. But I had a custom function on my class called "move". For some reason, it was getting called when the app was resumed, I had to do basically the same thing that you did and check to see if the game is paused to even let my objects move.
ColdLogic
finally traced what was happening. I had custom rotate code that would tell the uiviews to update their move function. When the app started back up, the os sent the change in orientation messages to it, the app thought it had rotated, so it called these functions and in turn cause my uianimations to start up. (just in case you were wondering)
ColdLogic