二进制运算符'|' 不能应用于两个UIViewAutoresizing操作数
在Swift 2.0中得到这个错误。
二进制运算符'|' 不能应用于两个UIViewAutoresizing操作数
这里是代码:
let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 568)) addSubview(view) view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
任何想法可能是什么问题?
OptionSetType
获得了Swift 2.x的更新语法和Swift 3.x的另一个更新
Swift 3.x
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
Swift 2.x
view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
这是Swift 1.2和2之间的区别:
// swift 1.2 view.autoresizingMask = .FlexibleWidth | .FlexibleTopMargin // swift 2 view.autoresizingMask = [.FlexibleWidth, .FlexibleTopMargin]
尝试使用xcode7-b6:
view.autoresizingMask = UIViewAutoresizing.FlexibleWidth.union(UIViewAutoresizing.FlexibleHeight)
对于Swift 3
Xcode 8 b1
:
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
实际为快速3.0.2:
view.autoresizingMask = [.layerWidthSizable, .layerHeightSizable]
在Xcode 7.2中使用这个代码swift 2
self.view.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleTopMargin]