CGRect在viewDidLoad之外的闭包中不起作用

问题描述 投票:0回答:1

我正在尝试使用CGRect制作矩形形状,然后在工作成功后返回它,这将允许我对其设置约束以将其放置在所需的位置,我在此闭包内部使用了它,给我一个错误。这放在我的viewDidLoad

之外
let logo : UIImageView = {
let myLogo = UIImageView(frame: CGRect(x: 0, y: 0, width: self.view.frame.height*(77/812)*2.078, height:  self.view.frame.height*(77/812)))

    myLogo.image = #imageLiteral(resourceName: "ftrLogo")
    return myLogo

}()
ios swift uiimageview closures cgrect
1个回答
1
投票

[您可能应该使徽标成为懒惰的变量。这样做:

    lazy var logo : UIImageView = {

    let myLogo = UIImageView(frame: CGRect(x: 0, y: 0, width: self.view.frame.height*(77/812)*2.078, height:  self.view.frame.height*(77/812)))

        myLogo.image = #imageLiteral(resourceName: "ftrLogo")
        return myLogo

    }()
© www.soinside.com 2019 - 2024. All rights reserved.