I'm reading a book on animations iOS Core Animation: Advanced Techniques. The book is in Objective C. I'm not fluent in Objective C. I understand what the .m34 property does but when I apply the book's code to Swift the perspective isn't changing. The problem is I cannot seem to add to an existing transform like explained here.
My code:
var tranform = CATransform3DIdentiy
transfrom.m34 = -1 / 500
transform = CATransform3DMakerotation(CGFloat(Double.pi/4), 0, 1, 0) // this is just creating a new transform instead of adding to the existing one
viewIwantTransformed.layer.transfrom = transform
Books Code:
@implementation ViewController
- (void) viewDidLoad
{ [super viewDidLoad];
// create a new transform CATransform3D
transform = CATransform3DIdentity;
// apply perspective
transform.m34 = - 1.0 / 500.0;
// rotate by 45 degrees along the Y axis
transform = CATransform3DRotate( transform, M_PI_4, 0, 1, 0);
// apply to layer
self.viewIwantTransformed.layer.transform = transform;
} @end
Result
try this
transform = CATransform3DRotate(transform, M_PI_4, 0, 1, 0)
instead by
transform = CATransform3DMakerotation(CGFloat(Double.pi/4, 0, 1, 0)