细分错误:11,xcode -12

帕夫·巴克

该应用程序在xcode 11上运行,但是一旦我在xcode 12上运行它,就会出现细分错误:11错误。

表单调试发现问题出在此函数中,如果我评论该代码可以正常工作,那么对我来说似乎没有任何错误,是否发生了什么?

open func addViewController(_ vc:UIViewController)->Void{
    
    controllers.append(vc)
    
    // Setup the viewController view
    
    vc.view.translatesAutoresizingMaskIntoConstraints = false
    scrollview.addSubview(vc.view)
    
    // Constraints
    
    let metricDict = ["w":vc.view.bounds.size.width,"h":vc.view.bounds.size.height]
    
    // - Generic cnst
    
    vc.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[view(h)]", options:[], metrics: metricDict, views: ["view":vc.view] as [String: UIView]))
    vc.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[view(w)]", options:[], metrics: metricDict, views: ["view":vc.view] as [String: UIView]))
    scrollview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[view]|", options:[], metrics: nil, views: ["view":vc.view] as [String: UIView]))
    
    // cnst for position: 1st element
    
    if controllers.count == 1{
        scrollview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[view]", options:[], metrics: nil, views: ["view":vc.view] as [String: UIView]))
        // cnst for position: other elements
    } else {
        
        let previousVC = controllers[controllers.count-2]
        if let previousView = previousVC.view {
            // For this constraint to work, previousView can not be optional
            scrollview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[previousView]-0-[view]", options:[], metrics: nil, views: ["previousView":previousView,"view":vc.view] as [String: UIView]))
        }
        
        if let cst = lastViewConstraint {
            scrollview.removeConstraints(cst)
        }
        lastViewConstraint = NSLayoutConstraint.constraints(withVisualFormat: "H:[view]-0-|", options:[], metrics: nil, views: ["view":vc.view] as [String: UIView])
        scrollview.addConstraints(lastViewConstraint!)
    }
}
Sh_Khan

像这样的部分代码

let metricDict = ["w":vc.view.bounds.size.width,"h":vc.view.bounds.size.height]

["view":vc.view] as [String: UIView]

["previousView":previousView,"view":vc.view] as [String: UIView]

可能会导致该问题,因此您可以尝试进行轻量级的分段工作,以便编译器可以通过它

open func addViewController(_ vc:UIViewController)->Void{
    
    controllers.append(vc)
    
    // Setup the viewController view
    
    vc.view.translatesAutoresizingMaskIntoConstraints = false
    scrollview.addSubview(vc.view)
    
    // Constraints
    
    let metricDict:[String:CGFloat] = ["w":vc.view.bounds.size.width,"h":vc.view.bounds.size.height]
    
    // - Generic cnst
    
    let con:[String: UIView] = ["view":vc.view]
    
    vc.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[view(h)]", options:[], metrics: metricDict, views: con ))
    vc.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[view(w)]", options:[], metrics: metricDict, views: con ))
    scrollview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[view]|", options:[], metrics: nil, views: con ))
    
    // cnst for position: 1st element
    
    if controllers.count == 1{
        scrollview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[view]", options:[], metrics: nil, views: con))
        // cnst for position: other elements
    } else {
        
        let previousVC = controllers[controllers.count-2]
        let relt:[String: UIView] = ["previousView":previousView,"view":vc.view]
        if let previousView = previousVC.view {
            // For this constraint to work, previousView can not be optional
            scrollview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[previousView]-0-[view]", options:[], metrics: nil, views:relt ))
        }
        
        if let cst = lastViewConstraint {
            scrollview.removeConstraints(cst)
        }
        lastViewConstraint = NSLayoutConstraint.constraints(withVisualFormat: "H:[view]-0-|", options:[], metrics: nil, views: con)
        scrollview.addConstraints(lastViewConstraint!)
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章