开发者

How do I get UIView autoresize rules to fire at viewDidLoad?

开发者 https://www.devze.com 2023-03-05 16:27 出处:网络
I\'ve created an开发者_如何学运维 iPad-targeted UIView in Interface Builder with struts and springs.Autoresizing works perfectly once the app is running, as I change the device orientation.But at star

I've created an开发者_如何学运维 iPad-targeted UIView in Interface Builder with struts and springs. Autoresizing works perfectly once the app is running, as I change the device orientation. But at startup, the UIView has its landscape sizing (as drawn in my xib) regardless of the orientation the device starts in. How do I get the autoresize rules to fire at viewDidLoad so that the view takes its portrait form if the user starts the app with the device in its portrait orientation?

Thanks!


The setFrame call doesn't work from me - because simply calling mainViewController.view causes viewDidLoad to be triggered before the setFrame is processed.

However, inside the viewDidLoad for your main view controller, you can call this before you do other calculations:

[self.view setFrame:[[UIScreen mainScreen] applicationFrame]];


This is actually really easy. In your AppDelegate, just send your main view controller's view a message to set the frame, like the following:

[mainViewController.view setFrame:self.window.frame];
0

精彩评论

暂无评论...
验证码 换一张
取 消