I would like to know how to solve a problem I’m having. I have an image sequence that basically animates a switch.

I’d like to implement this in iOS. How would you advise me to go for that? Maybe using UIButton? Or rather UISwitch?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a rather simple solution (tap switches, no swiping possible), I would advise you to use two UIViews stacked.
-1- At the bottom, use a
UIImageViewwhich allows you to run image animations.-2- At the top, use a
UIControlwhich will capture the touché-up-inside events.Alternatively, you could use a
UITapGestureRecognizeras a replacement for -2-. The latter option should only be considered if the resulting control will not be used for iOS < 3.2.As soon as your tap-recognizer (
UIControlorUITapGestureRecognizer) receives the tap-event, you simply play the animation provided through yourUIImageView.For more details on animations using UIImageView see its class reference, specifically on things like
animationImages(an array of images).As UIImageView does not provide you with a reverse animation feature, you will have to assign the images in the reverse order before animating back to the start (that is after a user switched it on and now switches back to off).
For a more complex solution (tap switches, swiping is possible), you may add a
UISwipeGesture Recognizerto your custom control and use the status of thatUIGestureRecognizerto select the currently visible image of yourUIImageView.