Wrong frame value while accessing the view from st

2019-03-18 15:07发布

问题:

I am accessing the size of the frame of view from storyboard. Below is my code for accessing frame property from storyboard.

SmallView *smallView = [self.storyboard instantiateViewControllerWithIdentifier:@"SmallView"];
CGRect frame = smallView.view.frame;
self.containerView.frame = frame;

In story board the frame size of the view is (200,400). But when I am accessing the frame size from the code it's always giving (320,460).Why? In the above code I got small view object from storyboard so what will be the value of view's frame in story board that should be shown but it's not showing.Always it's showing (320,460).

For quick debugging you can check the below source code .

https://dl.dropbox.com/u/90940570/FrameTest.zip

回答1:

Uncheck the "Resize View From Nib" box in the inspector. That should give you the correct size for a freeform view controller.



回答2:

Gettings a frame of a viewController's view which might not even displayed is not a good practice. The point where you can assume, everything is in place is the viewControllers's ViewDidLoad method.