Swift iOS - 在使用CATransform3D .m34属性更改Swift中的透视图时,应用其他更改进行转换

时间:2018-05-31 13:20:17

标签: ios swift catransform3d

我正在阅读一本关于动画的书iOS Core Animation: Advanced Techniques。这本书是在目标C中。我对目标C不熟悉。我理解.m34属性的作用但是当我将书的代码应用于Swift时,这个观点并没有改变。问题是我似乎无法添加到像explained here这样的现有转换。

我的代码:

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

结果

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个

transform = CATransform3DRotate(transform, M_PI_4, 0, 1, 0) 

而不是

transform = CATransform3DMakerotation(CGFloat(Double.pi/4, 0, 1, 0)