Why is frame width of the view alway 600 by 600 with autolayout

后端 未结 3 880
我寻月下人不归
我寻月下人不归 2021-02-04 13:31

I am making a basic Minesweeper app for practice / fun in swift. I want to make it so the size of the board (10 tiles wide) adapts to any iOS screen.

To do this I\'m se

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 13:44

    When you are using auto-layout, the subviews are laid out after the viewDidLayoutSubviews function. Therefore, if you call tileContainer.frame.size before that, such as in viewDidLoad, it will always be 600 by 600 (which is the default size in storyboard).

    viewDidLayoutSubviews: Called to notify the view controller that its view has just laid out its subviews. reference

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
    
        print(tileContainer.frame.size); // This is actual size you are looking for
    }
    

提交回复
热议问题