繁体   English   中英

layoutIfNeeded导致崩溃

[英]layoutIfNeeded causes a crash

我有一个UITextView,它显示文本当文本不是很大时(我说的是100-200个单词),该应用程序运行正常

如果它有非常大的文本(大约10000个单词),它将不断崩溃

编码

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    check(scrollView)
    let scrollPos = textView.contentOffset.y

    if dragging { return }
    if isAppearanceOpened { return }

    if scrollPos > 0 {
        UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseInOut, animations: {
            if scrollPos <= self.contentOffset {
                self.topView.alpha = 1
                self.pageView.alpha = 1
                self.topViewHeight.constant = 70
            } else {
                self.topView.alpha = 0
                self.pageView.alpha = 0
                self.topViewHeight.constant = 0
            }
            self.view.layoutIfNeeded()
        }) { (_) in
            if !decelerate { self.recheckEditorPosition() }
        }
    } else {
        UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseInOut, animations: {
            self.topView.alpha = 1
            self.pageView.alpha = 1
            self.topViewHeight.constant = 70
        }) { (_) in
            if !decelerate { self.recheckEditorPosition() }
        }
    }
}

错误

EXC_BAD_ACCESS(代码= 2,地址= 0x16d2a7ef0)

控制台很清楚,所以我有点困惑如果我要删除self.view.layoutIfNeedee() ,则应用程序可以正常运行,但是缺少动画

因此,我从研究中得到了一个结果。崩溃是由textView contentInset引起的。 当左右inset为0时,它在大文本上运行良好,我的猜测是textView对齐方式,字体等的计算非常耗时,因此编译器给出了一个错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM