-1

这是开始使用的基本代码:

[UIView transitionWithView:self.view duration:2.0
                   options:UIViewAnimationOptionBeginFromCurrentState
                animations:^ {         

                    CALayer *layer1 = leftband.layer;
                    layer1.anchorPoint = CGPointMake(0, 0.5);
                    CATransform3D rotationAndPerspectiveTransform1 = CATransform3DIdentity;
                    rotationAndPerspectiveTransform1.m34 = 1.0 / -500;
                    rotationAndPerspectiveTransform1 = CATransform3DRotate(rotationAndPerspectiveTransform1, DegreesToRadians(-180.0f), 0.0f, 1.0f, 0.0f);
                    layer1.transform = rotationAndPerspectiveTransform1;

                    CALayer *layer2 = rightband.layer;
                    layer2.anchorPoint = CGPointMake(0, 0.5);
                    CATransform3D rotationAndPerspectiveTransform2 = CATransform3DIdentity;
                    rotationAndPerspectiveTransform2.m34 = 1.0 / -500;
                    rotationAndPerspectiveTransform2 = CATransform3DRotate(rotationAndPerspectiveTransform2, DegreesToRadians(180.0f), 0.0f, 1.0f, 0.0f);
                    layer2.transform = rotationAndPerspectiveTransform2;
                }
                completion:nil {

                }];

leftband 和 rightband 是两个 UIImageView。我想要的效果是leftband沿Y轴向左方向变换动画。右边带沿其 Y 轴向右做同样的事情。

但是上面的代码导致左右图像视图在同一方向上动画(它只发生在左边)。我想我对锚点的理解是错误的。旋转变换中的 -180° 和 +180° 都会产生向左的动画。

我在这里做错了什么?

4

1 回答 1

0

基本上在动画块运行之前设置锚点可以解决问题。左锚点 -> (0.0f,0.5f) 和右锚点 -> (1.0f,0.5f)。

于 2012-05-31T10:16:34.297 回答