本文介绍了雨燕2.0 constraintsWithVisualFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自动版式奇怪的问题,在雨燕2.0
I have strange problem with AutoLayout in Swift 2.0
self.webView = WKWebView()
self.view.addSubview(self.webView!)
var viewBindingsDict: NSMutableDictionary = NSMutableDictionary()
viewBindingsDict.setValue(self.webView, forKey: "webView")
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: 0, metrics: nil, views: viewBindingsDict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[webView]|", options: 0, metrics: nil, views: viewBindingsDict))
和我收到的错误:
'String' is not convertible to 'StringLiteralConvertible'
对于H:| [web视图] |和V:| [web视图] |
我不知道,如果即时缺少的东西。
I do not know if im missing something
更新:
推荐答案
您应该改变你的 viewBindigsDict
到
var viewBindingsDict = [String: AnyObject]()
viewBindingsDict["webView"] = webView
作为意见提出,也格式选项,则不能使用0,而不是:
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))
以上simplier为@MartinR建议:
or more simplier as @MartinR suggested:
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: [], metrics: nil, views: viewBindingsDict))
这篇关于雨燕2.0 constraintsWithVisualFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!