Domanda

In my current project I've created an app that utilizes the position of the UISlider in relation to a target value displayed to the user. I've got full functionality however I'm now trying to spice it up a bit.

Is it possible to set the UISlider to move from (minimum through maximum) than (maximum through minimum) back and forth on its own when the user enters the app rather than having them drag it?

Thoughts:

Possibly use a looping sequence?

Not looking for someone to code this for me I quite enjoy that part. Just looking for guidance.

È stato utile?

Soluzione

Further to the NSTimer answer, I wouldn't suggest using that, but CADisplayLink instead. Similar process, but instead of using NSTimer use CADisplayLink.

CADisplayLink synchronises with the screen refresh rate, so you can adjust the animation and slider value based on current frame, so the animation appears smooth.

http://patzearfoss.com/2011/09/02/more-cadisplaylink/

Altri suggerimenti

I think that in this case you would have to setup an NSTimer with a time that you wish per frame, separate out the action code within the slider into a routine that can be called by you, then within the timer action code, call your routine, and then set the slider position manually.

Look here for setting up an NSTimer

How do I use NSTimer?

The NSTimer will essentially allow you to setup any framerate you wish, AND keep it off of the MAIN thread.

UISlider has this method that allows you to programatically change the slider's value:

- (void)setValue:(float)value animated:(BOOL)animated

Be careful about using loops though, you don't want to block your main thread an make your app unresponsive.

Trumpetlick's answer provides good information on using an NSTimer, which should help you with this.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top