最新消息:20210917 已从crifan.com换到crifan.org

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

Swift crifan 2723浏览 0评论

【背景】

参考:

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]

才可以。

转载请注明:在路上 » 【已解决】swift代码出错:Binary operator | cannot be applied to two UIViewAutoresizing operands

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
94 queries in 0.191 seconds, using 23.30MB memory