ScrollView created in storyboard, initialized with frame 0,0,0,0

I created a UIScrollView in a storyboard, bound it as a property to the view controller, and now I'm trying to add some pagination subzones. But, although graphically I set the dimensions in the storyboard, the UIScrollView frame reaches 0,0,0,0. Do I have to rigidly set the dimensions, although I have already outlined them graphically in the storyboard?

Also, something like related, is it possible to customize subviews in a storyboard for use in this scroll? It seems that I cannot create such a view if it is not already in the controller. Since I have only one controller and potentially several views that I want to configure graphically, how can I do this without doing this programmatically?

+6
source share
5 answers

With pivoting versions of viewDidLayoutSubviews, you can find the size of all your views. viewWillAppear did not work for me and always returned (0,0,0,0);

+16
source

With downstream versions, the controller outputs are not connected before viewDidLoad, and its size is not set before viewWillAppear, see here:

http://cs193p.m2m.at/lecture-8/

Once the controller is fully created and its outputs connected viewDidLoad: is called. Therefore, this is a good place for installation code. However, the size of the controller has not yet been set, but in viewWillAppear: which is called immediately before the view screen.

So, I think the Enricos suggestion is correct. Just try placing the material associated with the size in viewWillAppear.

+3
source

I found out that when I access scrollview in viewWillAppear , the frame will actually give the correct numbers. I previously tried this in awakeFromNib and viewDidLoad and got a frame of 0,0,0,0 .

What is strange in front of the Storyboard, you can get the correct frame sizes in awakeFromNib. An example of this is one example of Apple PageControl code.

Therefore, to answer the question, try to get it from viewWillAppear (suppose you created a UIScrollView in a Storyboard).

+1
source

You probably set a breakpoint on the line where the view has not yet been set. Try the following:

 - (id)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { CGRect frame = self.scrollView.frame; NSLog (@"FRAME IS %@", NSStringFromCGRect(frame)); } return self; } 
0
source

It's quite simple: turn off the use of autorun in the storyboard settings.

Disable Use Autolayout in the Storyboard settings (red rectangle)

0
source

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


All Articles