3
[UIView beginAnimations:nil context:NULL]; // animate the following:
gearKnob.center = startedAtPoint;
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];

これは、UIImageView(gearKnob)をポイントからポイントに移動するアニメーションです。問題は、オブジェクトが移動しているときに、それに応じて背景を変更する必要があるため、移動しているときにすべてのUIImageView位置を追跡する必要があることです。どうすればその位置を追跡できますか?それを行う方法や委任はありますか?

4

3 に答える 3

9

本当に必要な場合は、これが効率的な方法です。秘訣は、CADisplayLink タイマーを使用して、layer.presentationLayer からアニメーション化されたプロパティを読み取ることです。

@interface MyViewController ()
...
@property(nonatomic, strong) CADisplayLink *displayLink;
...
@end

@implementation MyViewController {

- (void)animateGearKnob {

   // invalidate any pending timer
   [self.displayLink invalidate];

   // create a timer that's synchronized with the refresh rate of the display
   self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateDuringAnimation)];
   [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

   // launch the animation
   [UIView animateWithDuration:0.3 delay:0 options:0 animations:^{

       gearKnob.center = startedAtPoint;

   } completion:^(BOOL finished) {

       // terminate the timer when the animation is complete
       [self.displayLink invalidate];
       self.displayLink = nil;
   }];
}

- (void)updateDuringAnimation {

    // Do something with gearKnob.layer.presentationLayer.center

}

}
于 2014-01-24T22:27:13.270 に答える
1

David が書いたように、2 つ目のアニメーションを並行して実行した方がよいでしょう。

タイマーを使用して何かを擬似的にアニメーション化する必要がある場合は、コールバックのベジエ タイミング カーブを設定できるCPAccelerationTimerを試してください。

本当に必要な場合は、 でキー値の監視を実行できるはずですgearKnob.layer.presentationLayer.center-[CALayer presentationLayer]によって返されるレイヤーは、「現在画面に表示されているレイヤーの近似値です。アニメーションの進行中に、このオブジェクトを取得し、それを使用してそれらのアニメーションの現在の値を取得できます。」</p>

于 2013-01-31T10:08:04.000 に答える
0

その場合、直接アニメーションを使用することはできません独自のタイマーを使用してノブを移動する必要があります: NSTimer timerWithTimeInterval: を使用し、セレクターでノブを移動して位置を取得します

于 2013-01-31T09:56:23.350 に答える