Search code examples
objective-ccore-animation

How can I create a onEnterFrame animation in Objective-C?


I'm trying to create interactivity inside an iPad app.

I would like to spin an image gallery, I would use a pan or swipe move to set the speed and let it decrease with the time.

Since I come from Actionscript world I would use onEnterFrame handler to do so, but I dont know how can I do that in Objective-C

EDIT: The movement I want to add is similar to a coverflow menu.

My question is: How can I efficiently execute code inside a method which is executed on every frame ( or similar to onEnterframe ) ?

Thanks!


Solution

  • Since you are talking about frames I'm assuming that you want to do UI code for very frame.

    Custom drawing every "frame"

    You could execute code for every frame by implementing a custom view and use a NSTimer that fires 60 times a second and calls [self setNeedsDisplay];. Now your custom views drawRect: method will be called for every frame.

    Now you have code that executes every frame. I would say that this probably isn't the most efficient way of doing things, especially if you don't change the view between every frame.

    Callbacks from the gesture recognizer

    The gesture recognizer gives you callbacks whenever the user swipes or pans. If you only want to move your views in response to the this then putting your code in these methods will work fine.

    Using this approach you will only execute your code when there are changes to respond to.

    Cover flow using Core Animation

    If it is something similar to cover flow that you are trying to do then you could most likely do it using Core Animation. It is a bit to complicated to describe exactly how to do it here and besides I don't know the details of how you want it to look but there are many good resources on the web that describe how you can create something like Cover flow.

    One resource is the Core Animation screencasts by Bill Dudney where he creates a Cover flow UI with Core Aniation. It is a few years old and is aimed towards the Mac but most of it still applies to iOS.