UIViewをプルアップしてスワイプして画面をアニメーション表示します。私はそれを行うためにこのコードを使用します:一時停止したアニメーションとNSInternalInconsistencyExceptionのためにアプリケーションがクラッシュする
private var _animator: AnyObject?
@available(iOS 10.0, *)
var animator: UIViewPropertyAnimator? {
get {
return _animator as? UIViewPropertyAnimator
}
set {
_animator = newValue
}
}
var haveTheySwiped = false
var haveTheyNotSwiped = true
@available(iOS 10.0, *)
func handlePan(recognizer: UIPanGestureRecognizer) {
let vel = recognizer.velocity(in: self)
switch recognizer.state {
case .began:
if vel.y < 0 && !haveTheySwiped {
animator = UIViewPropertyAnimator(duration: 1, curve: .easeOut, animations: {
self.backgroundImage.frame = self.backgroundImage.frame.offsetBy(dx: 0, dy: -603)
})
haveTheySwiped = true
isScanVisible = true
} else if vel.y > 0 && haveTheySwiped {
animator = UIViewPropertyAnimator(duration: 1, curve: .easeOut, animations: {
self.backgroundImage.frame = self.backgroundImage.frame.offsetBy(dx: 0, dy: 603)
})
haveTheySwiped = false
isScanVisible = false
}
animator?.pauseAnimation()
print(backgroundImage.frame.origin)
case .changed:
let translation = recognizer.translation(in: backgroundImage)
if vel.y < 0 {
animator?.fractionComplete = translation.y/-603
} else if vel.y > 0 && haveTheySwiped == true {
animator?.fractionComplete = translation.y/603
}
case .ended:
animator?.continueAnimation(withTimingParameters: nil, durationFactor: 0)
case .possible: break
default: break
}
}
しかし、最近私はバグに出くわしました。私はプルアップしようとすると、UIViewのは表示されず、私は私の指を持ち上げるときに、このエラーでアプリがクラッシュ:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'It is an error to release a paused or stopped property animator. Property animators must either finish animating or be explicitly stopped and finished before they can be released.'
は、誰もがこれに遭遇していますか?これが起こる原因を解明するのに役立つでしょう。どんな助けも非常に高く評価されます。事前にありがとう!
乾杯、 Thoe
コメントを@solenoidおかげでそんなに!アニメーションをトリガするのではなく、実際にビューに結び付けられています。あなたが話していることを明確にすることはできますか? –
エラーは、基本的には「ちょっと、私が別のスレッドで実行しているので、何らかの方法でコールバック(適切な方法で終了または取り消された)が行われるまで、私を解放しないでください」と言っています。 代わりに、ジェスチャー認識機能の入力を使用して、入力したビューを指で移動してください。私は今それをテストすることはできませんが、その周りの例があるはずです。 – solenoid
@ソレノイドは私のコードのどの部分がそれをするのか知っていますか?ちょっと混乱します... hahaha –