ios 二元运算符“|” 不能应用于两个 UIViewAutoresizing 操作数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30867325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Binary operator '|' cannot be applied to two UIViewAutoresizing operands
提问by Khawar
Getting this error in Swift 2.0.
在 Swift 2.0 中出现此错误。
Binary operator '|' cannot be applied to two UIViewAutoresizing operands
二元运算符“|” 不能应用于两个 UIViewAutoresizing 操作数
Here is the code:
这是代码:
let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 568))
addSubview(view)
view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
Any idea what can be the problem?
知道可能是什么问题吗?
回答by keithbhunter
The OptionSetType
got an updated syntax for Swift 2.x and another update for Swift 3.x
在OptionSetType
得到了斯威夫特2.X更新的语法和斯威夫特3.x的另一个更新
Swift 3.x
斯威夫特 3.x
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
Swift 2.x
斯威夫特 2.x
view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
回答by Jorge Casariego
This are the differences between Swift 1.2 and 2:
这是 Swift 1.2 和 2 之间的区别:
// swift 1.2
view.autoresizingMask = .FlexibleWidth | .FlexibleTopMargin
// swift 2
view.autoresizingMask = [.FlexibleWidth, .FlexibleTopMargin]
回答by Tai Le
Try with xcode7-b6:
尝试使用 xcode7-b6:
view.autoresizingMask = UIViewAutoresizing.FlexibleWidth.union(UIViewAutoresizing.FlexibleHeight)
回答by David DelMonte
For Swift 3
Xcode 8 b1
:
对于Swift 3
Xcode 8 b1
:
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
回答by Liza Povalyaeva
actual for swift 3.0.2:
swift 3.0.2 的实际情况:
view.autoresizingMask = [.layerWidthSizable, .layerHeightSizable]
回答by Maninderjit Singh
use this code swift 2 with Xcode 7.2
将此代码 swift 2 与 Xcode 7.2 一起使用
self.view.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleTopMargin]