Barry B
Barry B

Reputation: 47

Get actual view size after setting constraints

How do I get the actual view size? Right now I am getting it from gameView.frame.size. It does give me the right values that I set, but it doesn't give me the actual size.

For example, in my storyboard I have an iPhone 11 and I draw a frame of width:375 and height:375 with constraints.

And now I simulate an iPad and the frame indeed does have the right constraints, but it is still giving me back the values 375-375 but that isn't the actual size.

Upvotes: 1

Views: 1657

Answers (1)

Mohammad Assad Arshad
Mohammad Assad Arshad

Reputation: 1784

You have a couple of options; based on your use case:

  1. Get your frame by using:

    DispatchQueue.main.async {
      //print(self.view.frame)
    }
    
  2. get your updated frame values in viewDidAppear

  3. get your updated frame values in viewDidLayoutSubviews. But be careful this is called multiple times.

Upvotes: 1

Related Questions