Swift 2.0 constraintsWithVisualFormat

后端 未结 1 648
终归单人心
终归单人心 2021-02-13 23:20

I have strange problem with AutoLayout in Swift 2.0

self.webView = WKWebView()
self.view.addSubview(self.webView!)

var viewBindingsDict: NSMutableDictionary = N         


        
相关标签:
1条回答
  • 2021-02-13 23:50

    You should change your viewBindigsDict to

    var viewBindingsDict = [String: AnyObject]()
    viewBindingsDict["webView"] = webView
    

    as suggested in the comments, and also in the format options, you cannot use 0, instead:

    view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewBindingsDict))
    

    or more simplier as @MartinR suggested:

    view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: [], metrics: nil, views: viewBindingsDict))
    
    0 讨论(0)
提交回复
热议问题