Wrong frame value while accessing the view from storyboard in IOS

筅森魡賤 提交于 2019-12-20 19:57:33

问题


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.



来源:https://stackoverflow.com/questions/14520561/wrong-frame-value-while-accessing-the-view-from-storyboard-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!