Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 连续旋转不居中_Ios_Swift_Autolayout - Fatal编程技术网

Ios 连续旋转不居中

Ios 连续旋转不居中,ios,swift,autolayout,Ios,Swift,Autolayout,使用此代码: UIView.animate(withDuration: 0.5, delay: 0, options: [.repeat], animations: { self.star.transform = self.star.transform.rotated(by: CGFloat(M_PI_2)) }) extension UIView { func rotate360Degrees(duration: CFTimeInterval = 3)

使用此代码:

    UIView.animate(withDuration: 0.5, delay: 0, options: [.repeat], animations: {
        self.star.transform = self.star.transform.rotated(by: CGFloat(M_PI_2))
    })
extension UIView {
    func rotate360Degrees(duration: CFTimeInterval = 3) {
        let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
        rotateAnimation.fromValue = 0.0
        rotateAnimation.toValue = CGFloat(M_PI * 2)
        rotateAnimation.isRemovedOnCompletion = false
        rotateAnimation.duration = duration
        rotateAnimation.repeatCount=Float.infinity
        self.layer.add(rotateAnimation, forKey: nil)
    }
}
我的观点是:

使用此代码:

    UIView.animate(withDuration: 0.5, delay: 0, options: [.repeat], animations: {
        self.star.transform = self.star.transform.rotated(by: CGFloat(M_PI_2))
    })
extension UIView {
    func rotate360Degrees(duration: CFTimeInterval = 3) {
        let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
        rotateAnimation.fromValue = 0.0
        rotateAnimation.toValue = CGFloat(M_PI * 2)
        rotateAnimation.isRemovedOnCompletion = false
        rotateAnimation.duration = duration
        rotateAnimation.repeatCount=Float.infinity
        self.layer.add(rotateAnimation, forKey: nil)
    }
}
我的观点是:

两人都不是我想要的。正在旋转的视图是要填充比例的UIImageView。我希望图像保持在中间。我怎样才能做到这一点?这些函数在ViewDidDisplay中执行。最后一张gif看起来好多了,但请注意星星并没有完全居中

问题 你图像的中心不是你的星星的中心

解决 有两种可能的解决办法

  • 编辑图像,使星星的中心位于图像的中心
  • 将旋转层的锚定点设置到恒星的中心(x:1004px,y:761px)
问题 你图像的中心不是你的星星的中心

解决 有两种可能的解决办法

  • 编辑图像,使星星的中心位于图像的中心
  • 将旋转层的锚定点设置到恒星的中心(x:1004px,y:761px)