CATransform3DRotate effects gone after applying anchor point

空扰寡人 提交于 2020-01-16 04:43:28

问题


EDIT with correct observation.

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.

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.

Any suggestions?

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

回答1:


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

Otherwise it starts from the beginning again.

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


来源:https://stackoverflow.com/questions/16908331/catransform3drotate-effects-gone-after-applying-anchor-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!