DGElasticPullToRefresh - 由于信号导致命令失败:分段错误:11

时间:2018-05-28 08:51:01

标签: swift xcode compiler-errors

通过Pods导入DGElasticPullToRefresh Lib后,我的编译器崩溃了。它是由DGElasticPullToRefreshView.swift的这个函数引起的:

 override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    if keyPath == DGElasticPullToRefreshConstants.KeyPaths.ContentOffset {
        if let newContentOffset = change?[NSKeyValueChangeKey.newKey], let scrollView = scrollView() {
            let newContentOffsetY = (newContentOffset as AnyObject).cgPointValue.y
            if state.isAnyOf([.loading, .animatingToStopped]) && newContentOffsetY < -scrollView.contentInset.top {
                scrollView.contentOffset.y = -scrollView.contentInset.top
            } else {
                scrollViewDidChangeContentOffset(dragging: scrollView.isDragging)
            }
            layoutSubviews()
        }
    } else if keyPath == DGElasticPullToRefreshConstants.KeyPaths.ContentInset {
        if let newContentInset = change?[NSKeyValueChangeKey.newKey] {
            let newContentInsetTop = (newContentInset as AnyObject).uiEdgeInsetsValue.top
            originalContentInsetTop = newContentInsetTop
        }
    } else if keyPath == DGElasticPullToRefreshConstants.KeyPaths.Frame {
        layoutSubviews()
    } else if keyPath == DGElasticPullToRefreshConstants.KeyPaths.PanGestureRecognizerState {
        if let gestureState = scrollView()?.panGestureRecognizer.state, gestureState.dg_isAnyOf([.ended, .cancelled, .failed]) {
            scrollViewDidChangeContentOffset(dragging: false)
        }
    }
}

根据这篇文章:https://stackoverflow.com/a/41043678/6003494我可以识别导致错误的行。它是第二个if子句中的这一行:

let newContentInsetTop = (newContentInset as AnyObject).uiEdgeInsetsValue.top

任何人都知道如何解决这个问题?感谢。

1 个答案:

答案 0 :(得分:0)

我可以在测试2小时后修复它:我不得不将类型转换为NSValue:

由此:

let newContentInsetTop = (newContentInset as AnyObject).uiEdgeInsetsValue.top

到此:

let newContentInsetTop = (newContentInset as! NSValue).uiEdgeInsetsValue.top