war*_*enm 37
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, rotationPoint.x-center.x, rotationPoint.y-center.y, 0.0);
transform = CATransform3DRotate(transform, rotationAngle, 0.0, 0.0, -1.0);
transform = CATransform3DTranslate(transform, center.x-rotationPoint.x, center.y-rotationPoint.y, 0.0);
Run Code Online (Sandbox Code Playgroud)
center图层的中心在哪里,rotationAngle以弧度为单位(正向为逆时针方向),并且rotationPoint是您想要旋转的点.center并且rotationPoint位于包含视图的坐标空间中.
bounds,position在superlayer和anchorPoint。anchorPoint具有相对坐标并指向anchorPoint。您的子层将围绕此旋转anchorPoint;例如,要在其父视图的顶部中心点上围绕子层的底部中心旋转子层,请使用以下代码:
// 1
let rect = CGRect(x: 0,
y: 0,
width: 20,
height: 20)
let path = UIBezierPath(rect: rect)
let sublayer = CAShapeLayer()
sublayer.fillColor = UIColor.green.cgColor
sublayer.path = path.cgPath
superlayer.addSublayer(sublayer)
// 2
sublayer.bounds = rect
sublayer.position = CGPoint(x: superlayer.bounds.size.width/2, y: 0)
sublayer.anchorPoint = CGPoint(x: 0.5, y: 1)
// 3
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.toValue = 2*CGFloat.pi
rotationAnimation.duration = 3
rotationAnimation.fillMode = kCAFillModeForwards
rotationAnimation.isRemovedOnCompletion = false
sublayer.add(rotationAnimation, forKey: nil)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14179 次 |
| 最近记录: |