Objective-c CATransform3DMakeRotation Clockwise/Co

2019-06-10 18:30发布

问题:

I'm rotating an UIView along the x axis using CATransform3DMakeRotation using the below code:

  float radians = DegreesToRadians(30);
    [UIView animateWithDuration:0.15 animations:^{  
        self.moveControlView.layer.transform = CATransform3DMakeRotation(radians,1,0,0);
    }];

The rotation is applied always in the same versus (clockwise). I want to rotate the UIView in the opposite versus. In order to achieve my goal I've tried:

  • Set a negative angle (-30)
  • Set the angle to 330

But the versus of the orientation doesn't change.

I have also try to set x = -1 leaving the angle positive.

Any suggestion?

回答1:

You should apply a perspective to your transform, as it's explained in the similar question:

CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 1.0 / -500;

self.moveControlView.layer.transform = 
CATransform3DRotate(perspectiveTransform, radians, 1.0f, 0.0f, 0.0f);;