__NSCFString nsli_lowerAttribute:intoExpression:withCoefficient:forConstraint: 这仅在 ios 10 中发生

chi*_*hah 2 swift ios10

我制作了一个在 ios 11 中运行良好的应用程序,但是当我尝试在 ios 10 中运行它时。它突然开始崩溃并出现此错误。

-[__NSCFType nsli_lowerAttribute:intoExpression:withCoefficient:forConstraint:]: unrecognized selector sent to instance 0x600000199cc0
Run Code Online (Sandbox Code Playgroud)

我试图解决问题,但不知道为什么会发生这种情况。在异常断点中,它显示我在下面的位置

 func showFullScreenLoading(inView objView:UIView?,withMsg strMsg:String = "Please wait!!!")
    {
        guard let view = objView else
        {
            return
        }

        let objParentView = UIView.init()
        objParentView.translatesAutoresizingMaskIntoConstraints = false
        objParentView.backgroundColor = UIColor.white.withAlphaComponent(0.2)
        objParentView.tag = -123456
        view.addSubview(objParentView)

        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[objParentView]|", options: [], metrics: nil, views: ["objParentView":objParentView])) //At this line exception error
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[objParentView]|", options: [], metrics: nil, views: ["objParentView":objParentView]))
}
Run Code Online (Sandbox Code Playgroud)

函数的调用

 func apiCalled(_ objOperation:TagApiOperation){

    self.currentRequest = objHomeViewModel.apiCallHome(objOperation: objOperation, withDictData: [:], withLoaderBlock: { (isStart) in
        if isStart{
            SINGLETON.showFullScreenLoading(inView: self.view) // I called this function in view did load and there will be no background thread are there
        }else{
            SINGLETON.hideFullScreenLoading(inView: self.view)
        }
    }) { (isStatus, strMsg, arrBanner) in

     }
}
Run Code Online (Sandbox Code Playgroud)

chi*_*hah 5

最后我得到了这个问题的解决方案,因为安全区域。ios 11 提供了安全区域,因此如果您有 ios 10 支持的应用程序,请禁用安全区域。