0

I'm having a weird issue with an iPad app I'm writing.

I want to add a UIToolbar to my main view controller (set as root view controller in the app delegate). Within this main view controller, I support only landscape orientations. When I set the frame for my toolbar, however, it seems that the ipad still thinks it's in portrait mode! What I mean by this is when I run this line:

[_toolbar setFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44)];

The width of the toolbar is only 768, rather than 1024, even though the width of the screen at this point is clearly 1024, because the toolbar extends across only 2/3 of the screen. I'm having similar problems with placing subviews, and getting really weird placement on my main view controller.

Has anyone else run into problems like this? If so, how did you fix it? Thanks!

4

1 回答 1

1

您应该使用视图的边界,而不是框架,并且您不应该在视图的生命周期中过早地执行代码。

如果您从控件的viewDidAppear调用您的代码,那么我想它会起作用。但是如果你从viewWillAppear调用你的代码,那就太早了。

于 2013-04-22T19:40:54.163 回答