ボタンを押しても回転を止めようとするまで、回転し続けたい画像があります。私はこれらのウェブサイトを試した:https://www.andrewcbancroft.com/2014/10/15/rotate-animation-in-swift/私は代表団にチャンスを与えなければならなかった、それを変更しようとするとクラッシュする とhttps://bencoding.com/2015/07/27/spinning-uiimageview-using-swift/は、ありがとうございました。Swiftでの回転イメージのアニメーション
Andrewcbancroft.com::次のコードはここにある
extension UIView {
func rotate360Degrees(duration: CFTimeInterval = 1.0, completionDelegate: AnyObject? = nil) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI * 2.0)
rotateAnimation.duration = duration
if let delegate: AnyObject = completionDelegate {
rotateAnimation.delegate = delegate //<- error "Cannot assign value of type 'AnyObject' to type 'CAAnimationDelegate?'"
}
self.layer.add(rotateAnimation, forKey: nil)
}
}
のようにデリゲートをキャストしよう! CAAnimationDelegateがエラーコードでアプリケーションをクラッシュする画像を回転しようとすると 'test.ViewController'(0x1074a0a60)型の値を 'CAAnimationDelegate'(0x10cede480)にキャストできませんでした。
Bending.com:
extension UIView {
func startRotating(duration: Double = 1) {
let kAnimationKey = "rotation"
if self.layer.animation(forKey: kAnimationKey) == nil {
let animate = CABasicAnimation(keyPath: "transform.rotation")
animate.duration = duration
animate.repeatCount = Float.infinity
animate.fromValue = 0.0
animate.toValue = Float(M_PI * 2.0)
self.layer.add(animate, forKey: kAnimationKey)
}
}
func stopRotating() {
let kAnimationKey = "rotation"
if self.layer.animation(forKey: kAnimationKey) != nil {
self.layer.removeAnimation(forKey: kAnimationKey)
}
}
}
私のviewDidLoadメソッドに回転を開始するために私の画像ビューを呼び出すようにしようと、何も起こりません。
誰もこれらのサイトのコードを読んでコードを書くつもりはありません。試したコードとエラーメッセージを投稿してください。 – Frankie
Ok更新しました – Petravd1994