The UIView is resized using an automatic layout, but getting its frame size at runtime is incorrect. Ios

When I post the frame size view (0.0,0.0,320.0,435.0) using the machine, it seems to be correct in iphone 5 (4 inches), and when I run in iphone 4s it seems to be correct due to auto power off, but when I get the value of its frame after execution at runtime appears "(0.0,0.0,320.0,435.0)" I can not get the size that changed after applying the automatic layout in iphone 4s? I want to get the size, because using this size, I can set the program size of the created custom view.

+5
source share
2 answers

Before you “get a real-size code,” insert the following code:

 yourView.setNeedsLayout() yourView.layoutIfNeeded() 
+13
source

I think that automatic linking did not have time to link your views by the time you call it. The automatic layout did not happen at the time of the call to the DidLoad view, because it was called immediately after loading the views, and only after that the views are placed in the view hierarchy of the view controller and, ultimately, are mocked up (in the view layoutSubviews method).

try this code

  //delegate method - (void) viewDidLayoutSubviews { NSLog(@"height=%f",self.myview.frame.size.height); } 
+8
source

Source: https://habr.com/ru/post/1208231/


All Articles