這兩天在寫一個效果,就需要用到CATransform3DMakeRotation旋轉(zhuǎn)180度
于是有了下面的代碼
UIView.animate(withDuration: 2, animations: {
imageView.layer.transform = CATransform3DMakeRotation(.pi, 0, 0, 1)// 旋轉(zhuǎn)
}) { (finished) in
imageView.removeFromSuperview()
}
可是發(fā)現(xiàn)無論如何都是順時針旋轉(zhuǎn)。。
查閱了相關(guān)資料發(fā)現(xiàn)CATransform3DMakeRotation是按最短路徑來選擇的。。
于是這樣就可以解決了
UIView.animate(withDuration: 2, animations: {
whiteImageView.layer.transform = CATransform3DMakeRotation(.pi + 0.01, 0, 0, 1)// 旋轉(zhuǎn)
}) { (finished) in
whiteImageView.removeFromSuperview()
}
原理就是多了0.01的距離嘛