次のように、ボールの動きをアニメーション化できます。
/// declare block for animating
@property (nonatomic, strong) void(^animationCompletion)(BOOL);
CGFloat static kAnimationDuration = 0.3;
...
/// you declare here next position
CGPoint myPoint = CGPointMake(x, y)
/// create weak of self to not make retain cycle
ClassName __weak weakSelf = self;
/// define completion block declared above.
/// this block is called when one step is done. look below this block.
self.animationCompletion = ^(BOOL finished) {
myPoint = CGPointMake... //next point to move to
if (myPoint == lastPoint/*or other check when to finish moving*/) {
weakSelf.animationCompletion = nil; /// nil your block to not call this again
}
/// call next animation with next step
UIView animateWithDuration:kAnimationDuration animations:^{
// animate to next point
} completion:weakSelf.animationCompletion; /// and call block itself to make some sort of loop.
}
/// here is first call of above block. you make first step here.
UIView animateWithDuration:kAnimationDuration animations:^{
// animate to next point
} completion:self.animationCompletion;
それは働いていますか?はい。iOS 用 Arcade Balls アプリを見てください。そこで使いました。