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

后端 未结 3 957
我寻月下人不归
我寻月下人不归 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:42

    While the accepted answers is a correct answer I thought I might at least say that you can force the view to draw itself before hitting viewDidAppear:.

    Either, you can in your viewDidLoad: call:

    view.setNeedsLayout()
    view.layoutIfNeeded()

    Or if you create it from "outside":

    let vc = UIViewController()
    let _ = vc.view

    or

    let vc = UIViewController()
    vc.view.setNeedsLayout()
    vc.view.layoutIfNeeded()

提交回复
热议问题