2

I want to move an image around the screen using the [UIView AnimatewithDuration: ...] block. There are about 24 parts of this movements where the image moves from one point to another and then another and so on.

The problem is that I have to write 24 stacked blocks, which makes it extremely difficult to write, read, debug and indent while keeping track of each closing curly brace, square bracket, etc.

Is there is a simpler way to do it? There must be some way, with a for loop or something similar.

bbarnhart
  • 6,620
  • 1
  • 40
  • 60
  • Have you thought about using CoreAnimation? Maybe a CAKeyframeAnimation would help make things simpler. – James P Aug 02 '13 at 17:51
  • just stop whatever you are doing and use cocos2d instead. – Ben Aug 02 '13 at 18:07
  • I've added an answer to the mentioned question here [The proper way of doing chain animations](http://stackoverflow.com/questions/17949511/the-proper-way-of-doing-chain-animations) which utilizes a third party library. This may solve your problem, too. – CouchDeveloper Aug 02 '13 at 19:10

1 Answers1

0

If your animations are generic enough, there's no reason you can't use a recursive function that calls itself on completion. You'd have to pass whatever parameters that differ between calls and be able to tell when you should stop animating.

When you have a bunch of code blocks, I tend to lean towards this approach.

The proper way of doing chain animations

It's cleaner and easier to read than nesting UIView animation blocks.

Community
  • 1
  • 1
JeffRegan
  • 1,322
  • 9
  • 25