应用锚点后,CATransform3DRotate效果消失了 [英] CATransform3DRotate effects gone after applying anchor point

查看:98
本文介绍了应用锚点后,CATransform3DRotate效果消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以正确的观察进行编辑。

EDIT with correct observation.

我使用以下两个片段来旋转UIImageView。在stage1之后,我得到了所需的3D效果:视图旋转(3D效果)并伸展了(更大的尺寸)。在stage2上,我尝试用右铰链摆动rightView。

I used the following two snippets to rotate an UIImageView. After the stage1, I got the desired 3D effect: the view rotate (3D effect) and stretched out (larger size). On stage2, I am trying to swing the rightView with the hinge on the right.

如果我应用了更改锚点的线,则视图会正确摆动(右)有一个主要问题:在(旋转)3D效果仍然完好无损之后,视图的大小又恢复为原始大小(较小)。

If I applied the line that changes the anchor point, the view swings correctly (hinge on right) with one major issue: The view's size got restored back to original size (smaller) while the (rotation) 3D effect is still intact and then the swinging occurs.

有什么建议吗?

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) {
    }];
}


推荐答案

您需要添加 options添加到带有持续时间的动画中,并添加 options:UIViewAnimationOptionBeginFromCurrentState

You need to add the "options" to your animate with duration and add options:UIViewAnimationOptionBeginFromCurrentState

否则,它会从头开始。

所以您的阶段2看起来像这样:

So your stage 2 would look like this:

-(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) {
    }];
}

这篇关于应用锚点后,CATransform3DRotate效果消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆