1

我有一个旋转的视图:

self.mainView.layer.transform = CATransform3DRotate(self.mainView.layer.transform, -M_PI / 2, 0, 0, 1);

我对其应用 CAKeyFrameAnimation :

    CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    bounceAnimation.fillMode = kCAFillModeBoth;
    bounceAnimation.removedOnCompletion = YES;
    bounceAnimation.duration = 0.4;
    bounceAnimation.values = @[
                               //[NSValue valueWithCATransform3D:CATransform3DMakeRotation(-M_PI / 2.0f, 0.0f, 0.0f, 1.0f)]
                               [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 0.01f)],
                               [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.1f)],
                               [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 0.9f)],
                               [NSValue valueWithCATransform3D:CATransform3DIdentity]];
    bounceAnimation.keyTimes = @[@0.0f, @0.5f, @0.75f, @1.0f];
    bounceAnimation.timingFunctions = @[
                                        [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                        [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                        [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.mainView.layer addAnimation:bounceAnimation forKey:@"bounce"];

当我将视图附加到它的超级视图时,动画在我的初始旋转应用到它之前应用到视图,并且在动画完成之后,然后应用旋转。

我将如何制作它,以便在动画发生之前应用我发布的第一段代码的旋转?那么当view附加到它的superview时,就已经出现旋转了,然后进行动画呢?

4

1 回答 1

1

您的参数实际上将设置转换值,因此您需要使用所需的组合转换。

你应该像这样将你的旋转与你的 transform3D 结合起来:

CATransform3D tranform1 = CATransform3DMakeScale(0.01f, 0.01f, 0.01f);
transform1 = CATransform3DRotate(transform1, -m_PI / 2.0f, 0.0f, 0.0f, 1.0f);
CATransform3D tranform2 = CATransform3DMakeScale(1.1f, 1.1f, 1.1f);
transform2 = CATransform3DRotate(transform2, -m_PI / 2.0f, 0.0f, 0.0f, 1.0f);
CATransform3D tranform3 = CATransform3DMakeScale(0.9f, 0.9f, 0.9f);
transform3 = CATransform3DRotate(transform3, -m_PI / 2.0f, 0.0f, 0.0f, 1.0f);

    bounceAnimation.values = @[
      [NSValue valueWithCATransform3D:transform1],
      [NSValue valueWithCATransform3D:transform2],
      [NSValue valueWithCATransform3D:transform3]];
于 2013-10-30T03:18:02.103 回答