transform
- 基于View的形变
UIView.animate(withDuration: 5.0, animations: {
//每次形变都是针对原点
self.childView.transform = CGAffineTransform(translationX: 50, y: 50)
self.childView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
self.childView.transform = CGAffineTransform(rotationAngle: 0.5)
//self.parentV.transform = CGAffineTransform.identity.translatedBy(x: -100, y: 0).rotated(by: 0.5).scaledBy(x: 0.5, y: 0.5)
}) { (complete) in
kLog("移动完成")
//可在已经形变的基础上做形变
self.childView.transform = self.parentV.transform.translatedBy(x: 50, y: 50)
self.childView.transform = self.parentV.transform.scaledBy(x: 0.5, y: 0.5)
self.childView.transform = self.parentV.transform.rotated(by: 0.5)
}
CoreGraphics库中CGAffineTransform初始化及用法
transform3D
- 基于View的形变
UIView.animate(withDuration: 5.0, animations: {
//以初始位置为基准,x轴y轴z轴移动相应d单位(平面上看不出z轴的变化)
self.parentV.transform3D = CATransform3DMakeTranslation(50, 50, 50)
//以初始位置为基准,x轴y轴z轴移动相应缩放比例(平面上看不出z轴的变化)
self.parentV.transform3D = CATransform3DMakeScale(0.5, 0.5, 0.5)
//以初始位置为基准,当x,y,z值为0时,代表在该轴方向上不进行旋转,当值为1时,代表在该轴方向上进行逆时针旋转,当值为-1时,代表在该轴方向上进行顺时针旋转
self.parentV.transform3D = CATransform3DMakeRotation(CGFloat(M_PI), 0, 1, 0)
}) { (complete) in
kLog("移动完成")
//可在已经形变的基础上做形变
self.parentV.transform3D = CATransform3DTranslate(self.parentV.transform3D, 50, 50, 50)
self.parentV.transform3D = CATransform3DScale(self.parentV.transform3D, 0.5, 0.5, 0.5)
self.parentV.transform3D = CATransform3DRotate(self.parentV.transform3D, CGFloat(M_PI), 0, 1, 0)
}
- 基于layer的形变
UIView.animate(withDuration: 5.0, animations: {
//每次形变都是针对原点
self.parentV.layer.transform = CATransform3DMakeScale(0.5, 0.5, 0.5)
self.parentV.layer.transform = CATransform3DMakeRotation(180, 1, 0, 0)
self.parentV.layer.transform = CATransform3DMakeTranslation(10, 10, 0)
}) { (complete) in
kLog("移动完成")
//可在已经形变的基础上做形变
self.parentV.layer.transform = CATransform3DScale(self.parentV.layer.transform, 0.5, 0.5, 0.5)
self.parentV.layer.transform = CATransform3DRotate(self.parentV.layer.transform, 180, 1, 0, 0)
self.parentV.layer.transform = CATransform3DTranslate(self.parentV.layer.transform, 10, 10, 0)
}
网友评论