[英]iOS ARKit - Calculate the degree of rotation of device in all three direction
[英]ios UIImageView rotation direction in swift at variable degree in clockwise direction
如果角度大於180°,只需將其拆分為兩個動畫即可。
您可以在CoreAnimation
的幫助下根據需要旋轉圖像,如下所示:
let angle = myDegreeValue
if let n = NumberFormatter().number(from: angle) {
let floatAngle = Double(truncating: n)
CATransaction.begin()
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.byValue = NSNumber(value: floatAngle * (Double.pi / 180))
rotationAnimation.duration = 2
rotationAnimation.isRemovedOnCompletion = true
CATransaction.setCompletionBlock {
self.blueNeedleImageView.transform = CGAffineTransform(rotationAngle: CGFloat(floatAngle * (Double.pi / 180)))
}
self.blueNeedleImageView.layer.add(rotationAnimation, forKey: "rotationAnimation")
CATransaction.commit()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.