我需要的是水平旋转图像,我正在使用UIView.animate并且工作正常,但问题是图像在旋转时的位置发生了变化。我试图使用锚点,但它没有用。
当图像旋转时,我需要做些什么来不改变位置?
这是我的代码:
UIView.animate(withDuration: duration, delay: 0.5, options:
[.repeat,.curveEaseInOut,.transitionFlipFromLeft], animations: {
targetView.transform = CGAffineTransform(scaleX: -1, y: 1);
}) { finished in
}
谢谢,
答案 0 :(得分:0)
我不确定是否会旋转它。我认为问题在于你的代码只是移动了它。
Swift 3,4
func rotateView(view:UIView) {
UIView.animate(withDuration: 0.25, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: { () -> Void in
view.transform = CGAffineTransform(rotationAngle: CGFloat.pi * .25)
}, completion: nil)
}
用法:
rotateView(targetView)
如果我完全错了,请告诉我。)