【发布时间】:2014-05-09 16:31:31
【问题描述】:
我想首先围绕它的左边缘旋转我的 UIView,然后围绕它的右边缘旋转。第一次旋转应该产生开门效果,一旦完成,第二次旋转应该开始。当第二次旋转完成时,效果应该就像视图在 z 平面中被推下一样。转换是手动动画的一部分,当然应该是无缝的。
凭直觉,我猜不可能使用锚点并连接发生在不同锚点的 2 个旋转(但如果我错了,请纠正我)。因此,我没有使用锚点,而是使用矩阵组合来产生“旋转”的效果。
第一次旋转很容易,但我不知道如何附加第二次。也许在应用第二次旋转之前,我应该在 y 坐标上向右平移并在 z 坐标上向下移动(使用 cos(90 - angle) * view.width 之类的东西)以到达右边缘的位置第一次旋转结束。然而我所做的尝试并没有成功。任何想法? 这是我到目前为止第一次轮换的内容:
-(void) transform:(float) percentage{
CATransform3D transform = CATransform3DIdentity;
//here I get the angle for the 1st rotation (percentage 0 -> angle 0; percentage 0.5 -> angle 45°
float angle = [self getFirstRotationAngle: percentage];
CATransform3D translateToRotateAt = CATransform3DMakeTranslation(myView.frame.size.width / 2.0, 0.0, 0.0);
CATransform3D rotation1 = CATransform3DIdentity;
rotation1.m34 = 1.0 / -500;
rotation1 = CATransform3DRotate(rotation1, angle, 0.0f, 1.0f, 0.0f);
CATransform3D translateBackToRotateAt = CATransform3DMakeTranslation(-myView.frame.size.width / 2.0, 0.0, 0.0f);
transform = CATransform3DConcat(translateToRotateAt, rotation1);
transform = CATransform3DConcat(transform , translateBackToRotateAt);
if (percentage > 0.5){
angle = [self getSecondRotationAngle: percentage];
// here I should get the second part of the transformation and concatenate it to the first part
}
myView.layer.transform = transform;
}
【问题讨论】:
标签: ios iphone cocoa-touch rotation transformation