1

計算が必要な回転および移動プロパティのUIView設定を含むの複雑な連続アニメーションが必要なため、標準のアニメーションはオプションではありません。CATransform3D

CALayerアニメーションを使用するようになりました。そしてこれを持ってください:

self.displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(update:)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

- (void)update:(CADisplayLink*)sender
{
    CGFloat elapsedTime = sender.timestamp - self.lastTimestamp;
    self.lastTimestamp = sender.timestamp;

    self.rotation += elapsedTime * 0.1;  // Factor determines speed.

    // This is just example for SO post; the real animation is more complicated!
    CATransform3D transform;
    transform = CATransform3DMakeRotation(self.rotation, 1.0, 0.0, 0.0);
    self.imageLayer.transform = transform;
}

これself.imageLayerは、画像CALayercontents設定され、ベースビューにサブレイヤーとして追加された です。

それは「少し」回転しますが、連続的にではなく、時々停止したり、少し逆回転したりするようです。

値がはるかにインクリメントされるため、新しい値を割り当てtransformても効果がないことがよくあるようです。self.rotationを追加し[self setNeedsDisplay]ても役に立ちませんでした。

私はCALayerまだ s をあまり使っていないので、非常に基本的なものが欠けていると思います。しばらくそれを見つけようとしましたが、私が見つけたすべての例は、私が望むものとはかけ離れているようです.

4

1 に答える 1

4
于 2015-06-22T18:10:31.453 に答える