1

我想做一个完整的旋转,但是图像交换到一半,我似乎无法做到这一点。完整的旋转可以在下面看到。除了漂亮的z轴东西,我怎么能做到一半呢?这是在 animateWithDuration 块(iOS4)

// Create perspective transformation
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0f / -zDistance;
myView.layer.transform = transform; //- 3d
myView.layer.transform = CATransform3DMakeRotation(M_PI, -1, 0, 0); 
4

1 回答 1

2

你可以用两个块来做到这一点:

// Rotate the second 'backside' view to 90 degrees and hide it
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0f / -zDistance;
mySecondView.layer.transform = transform;
mySecondView.layer.transform = CATransform3DMakeRotation(M_PI / 2, -1, 0, 0);
mySecondView.hidden = YES;

// Animate to 90 degrees
[UIView animateWithDuration:0.5 animations:^{
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = 1.0f / -zDistance;
    myView.layer.transform = transform;
    myView.layer.transform = CATransform3DMakeRotation(M_PI / 2, -1, 0, 0);

} completion:^{

    // Switch to the backside view
    myView.hidden = YES;
    mySecondView.hidden = NO;

    // Animate the remaining 90 degrees
    [UIView animateWithDuration:0.5 animations:^{
        CATransform3D transform = CATransform3DIdentity;
        transform.m34 = 1.0f / -zDistance;
        mySecondView.layer.transform = transform;
        mySecondView.layer.transform = CATransform3DMakeRotation(M_PI, -1, 0, 0);
    }
}

您还可以体验myView.layer.isDoubleSided隐藏视图背面的属性 - 尽管您仍然需要hidden在动画结束时切换标志,否则第一个视图的按钮仍然是可点击的。

希望这可以帮助!谢谢。

于 2011-12-29T14:04:03.827 回答