ホームボタンを押してアプリを再起動すると、アニメーションが停止しました。設定ボタンが回転しなくなり、まばたきのラベルが消えるだけです。ホームボタンを押したときにアニメーションが機能しなくなり、アプリが再起動されます
点滅アニメーション:
extension UILabel {
func startBlink() {
UIView.animate(withDuration: 0.8,
delay:0.0,
options:[.autoreverse, .repeat],
animations: {
self.alpha = 0
}, completion: nil)
}
}
回転アニメーション:ここでは、両方のアニメーションのための私のコードは、私はそれを実行
extension UIButton {
func startRotating() {
UIView.animate(withDuration: 4.0, delay: 0.0, options:[.autoreverse, .repeat,UIViewAnimationOptions.allowUserInteraction], animations: {
self.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
}, completion: nil)
}
}
:
override func viewDidLoad() {
super.viewDidLoad()
settingsButton.layer.cornerRadius = 0.5 * settingsButton.bounds.size.width
settingsButton.clipsToBounds = true
settingsButton.imageView?.contentMode = .scaleAspectFit
NotificationCenter.default.addObserver(self, selector: #selector(appMovedToForeground), name: Notification.Name.UIApplicationWillEnterForeground, object: nil)
}
func appMovedToForeground() {
tapToPlayLabel.startBlink()
settingsButton.startRotating()
print("DID")
}
をCALayerAnimationを追加することができますがあなたの代わりに '' willEnterForeground'のdidBecomeActive'通知を使用してみましたが?私はアニメーションが動作していると仮定していますが、コードは 'willEnterForeground'で呼び出されているので、アニメーションが表示されません – Malik
@マリックあなたは答えとしてあなたのコメントを追加する必要があります – klinger
私はそれがうまくいくと仮定しています。ヘッドアップをありがとう。ちょうど答えとして投稿 – Malik