【已解决】swift代码出错:Binary operator | cannot be applied to two UIViewAutoresizing operands

【背景】

参考:

MHTabBarController/MHTabBarController.m at master · hollance/MHTabBarController · GitHub

尝试把OC代码改为swift代码,借鉴的去实现自己的自定义的tab,结果代码:

class RecordTabBarController : UIViewController {   
    override func viewDidLoad() {
        super.viewDidLoad()       
        self.view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

出错:

RecordTabBarController.swift:17:71: Binary operator ‘|’ cannot be applied to two ‘UIViewAutoresizing’ operands

swift Binary operator cannot be applied to two operands

 

【解决过程】

1.搜:

swift Binary operator | cannot be applied to two UIViewAutoresizing operands

参考:

ios – Binary operator ‘|’ cannot be applied to two UIViewAutoresizing operands – Stack Overflow

去改为:

        self.view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]

即可。

 

【总结】

swift新语法,把:

self.view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

换成:

self.view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]

才可以。



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量