Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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 UIPropertyAnimator导致崩溃_Ios_Swift_Xcode_Animation - Fatal编程技术网

Ios UIPropertyAnimator导致崩溃

Ios UIPropertyAnimator导致崩溃,ios,swift,xcode,animation,Ios,Swift,Xcode,Animation,我正在经历一个由UIPropertyImmotor引起的奇怪的崩溃。我有UICollectionView和strechy标题的自定义布局,我使用UIPropertyAnimator在UICollectionView下拉时设置模糊动画 问题是,当我在再次按下某个场景后关闭该场景时,应用程序会崩溃,并显示以下消息: objc[11346]: Cannot form weak reference to instance (0x121eeda60) of class [APPLICATION_NAME]

我正在经历一个由UIPropertyImmotor引起的奇怪的崩溃。我有UICollectionView和strechy标题的自定义布局,我使用UIPropertyAnimator在UICollectionView下拉时设置模糊动画

问题是,当我在再次按下某个场景后关闭该场景时,应用程序会崩溃,并显示以下消息:

objc[11346]: Cannot form weak reference to instance (0x121eeda60) of class [APPLICATION_NAME].StrechyHeaderCollectionReusableView. It is possible that this object was over-released, or is in the process of deallocation.
当我回到代码中解释是什么导致了这次撞车时,是Denit的电话。不管怎样,我对UIPropertyImator的理解是正确的。没有animator.StopAnimationTrue由于UnreleasePropertyAnimator`,应用程序将崩溃

这是我的标题视图中的代码:

final class StrechyHeaderCollectionReusableView: UICollectionReusableView, Nibable {

    // some code...

    lazy var animator: UIViewPropertyAnimator = {
        UIViewPropertyAnimator(duration: 3.0, curve: .easeOut, animations: { [weak self] in
            self?.blurVisualEffectView.effect = UIBlurEffect(style: .dark)
        })
    }()

    override func awakeFromNib() {
        super.awakeFromNib()

        blurVisualEffectView.effect = nil
    }

    // some code...

    deinit {
        animator.stopAnimation(true)
    }
}
我正在从数据源+委托类更改animaiton分数,视觉效果视图位于自定义标题xib中

func scrollViewDidScroll(_ scrollView: UIScrollView) {

    // some code...

    let strechyHeader = headerView(in: collectionView)
    strechyHeader?.isBackButtonHidden = isBackButtonHidden

    if scrollView.contentOffset.y > 0 {
        strechyHeader?.animator.fractionComplete = 0
    } else {
        strechyHeader?.animator.fractionComplete = abs(scrollView.contentOffset.y) / 100
    }
}
有什么想法吗?谢谢你们

尝试在去初始化方法中调用finishAnimation:

guard animator.state==.active else{return} animator.stopAnimationfalse animator.finishAnimationat:。开始 UPD:

尽量不要使用懒惰的动画师:

私有var动画师:UIViewPropertyAnimator? 重写函数awakeFromNib{ super.awakeFromNib animator=UIViewPropertyAnimator 持续时间:3.0, 曲线输出, 动画:{[弱自我]在 self?.blurVisualEffectView.effect=UIBlurEffectstyle:.暗 } blurVisualEffectView.effect=nil }
谢谢,但不幸的是仍然崩溃。你能分享一下你是如何开始动画的,以及你是如何初始化你的blurVisualEffectView的吗?嗯,实际上弱者和懒惰者不能很好地混合。请尝试将动画制作为非惰性存储属性。我已经更新了我的答案