以下是开始使用的基本代码:
[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是两个UIImageViews。我想要的效果是左边带的动画沿着Y轴向左方向变换。右边的Y轴沿着右边做同样的事情。
但是上面的代码导致左右图像视图在同一方向上动画(它只发生在左侧)。我想我对锚点的理解是错误的。旋转变换中的-180°和+ 180°都导致向左动画。
我在这里做错了什么?
答案 0 :(得分:0)
基本上在动画块运行之前设置锚点可以解决问题。左边的锚点 - > (0.0f,0.5f)和右 - > (1.0F,0.5F)。