Swift iOS - 在使用 CATransform3D .m34 属性 改变视角时对变换应用额外的改变 Swift
Swift iOS -Apply additional changes to transform when using CATransform3D .m34 property to change perspective in Swift
我正在看一本关于动画的书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 。
我的代码:
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
书籍代码:
@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
结果
试试这个
transform = CATransform3DRotate(transform, M_PI_4, 0, 1, 0)
改为
transform = CATransform3DMakerotation(CGFloat(Double.pi/4, 0, 1, 0)
我正在看一本关于动画的书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
我的代码:
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
书籍代码:
@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
结果
试试这个
transform = CATransform3DRotate(transform, M_PI_4, 0, 1, 0)
改为
transform = CATransform3DMakerotation(CGFloat(Double.pi/4, 0, 1, 0)