CATransform3DRotate effects gone after applying an

2019-08-02 05:37发布

问题:

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