【问题标题】:CATransform3DRotate effects gone after applying anchor point应用锚点后 CATransform3DRotate 效果消失
【发布时间】:2013-06-04 01:15:51
【问题描述】:

用正确的观察进行编辑。

我使用以下两个 sn-ps 来旋转 UIImageView。在 stage1 之后,我得到了想要的 3D 效果:视图旋转(3D 效果)和拉伸(更大尺寸)。在 stage2 上,我正在尝试用右侧的铰链摆动 rightView。

如果我应用更改锚点的线,视图会正确摆动(右侧铰链),但存在一个主要问题:视图的大小恢复到原始大小(更小),而(旋转)3D 效果仍然完好无损然后发生摆动。

有什么建议吗?

rightView.layer.anchorPoint = CGPointMake(1.0, 0.5); 


-(void)stage1
{
    [UIView animateWithDuration:1.5  animations:^{
        rightView.transform = CGAffineTransformMakeTranslation(0,0);   //rightView i UIImageView
        CATransform3D _3Dt = CATransform3DIdentity;
        _3Dt =CATransform3DMakeRotation(3.141f/42.0f,0.0f,-1.0f,0.0f);  
        _3Dt.m34 = -0.001f;
        _3Dt.m14 = -0.0015f;
        rightView.layer.transform = _3Dt;
    } completion:^(BOOL finished){
        if (finished) {
            NSLog(@"finished..");
        }
    }];
}

-(void)Stage2
{
    rightView.layer.anchorPoint = CGPointMake(1.0, 0.5);   //issue?
    rightView.center = CGPointMake(1012, 384);
    [UIView animateWithDuration:1.75 animations:^{
        CATransform3D rightTransform = rightView.layer.transform;
        rightTransform.m34 = 1.0f/500; 
        rightTransform = CATransform3DRotate(rightTransform, M_PI_2, 0, 1, 0);
        rightView.layer.transform = rightTransform;
    } completion:^(BOOL finished) {
    }];
}

【问题讨论】:

  • 更改锚点也会改变应用转换的方式。您能否生成所需结果的图像,例如Photoshop?初始状态,stage1动画完成时的状态,stage2动画完成时的状态?
  • @hfossli,图片已添加。我还在 stage2 动画发生之前添加了一张图片。注意,我可以在 stage2 动画之前使用 setFrame 更改为 rightView 的帧,但是在 stage1 动画之后我无法让它匹配原始的 3D 效果(角度等)。
  • 你上传的图片是想要的输出还是“错误”的输出?
  • @hfossli,这是错误的。图片 4 是动画图片 3 而不是图片 2 的结果。图片 3,如您所见,anchorPoint 设置改变了图片 2 的大小。
  • 如果省略 rightView.center = CGPointMake(1012, 384); 会发生什么?还是放在动画里?我认为这会使视图在第二个动画开始之前跳转。

标签: ios catransform3d catransform3drotate


【解决方案1】:

您需要在动画中添加“选项”和持续时间并添加options:UIViewAnimationOptionBeginFromCurrentState

否则从头开始。

所以您的第 2 阶段将如下所示:

-(void)Stage2
{
    rightView.layer.anchorPoint = CGPointMake(1.0, 0.5);   //issue?
    rightView.center = CGPointMake(1012, 384);
    [UIView animateWithDuration:1.75
                          delay:0.00 
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
        CATransform3D rightTransform = rightView.layer.transform;
        rightTransform.m34 = 1.0f/500; 
        rightTransform = CATransform3DRotate(rightTransform, M_PI_2, 0, 1, 0);
        rightView.layer.transform = rightTransform;
    } completion:^(BOOL finished) {
    }];
}

【讨论】:

  • 我试过了,但结果是一样的。就像我原来的sn-p一样,如果我没有设置anchorPoint,那么原来的变换效果就完好无损。 anchorPoint 似乎是罪魁祸首。还有其他建议吗?
  • 我原来的观察是错误的。如果您仍然感兴趣,请查看更新。谢谢。
  • 就我而言,它是一层。有什么属性可以将 CABasicAnimation 设置为从图层的当前状态开始?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-10
  • 2021-05-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多