简体   繁体   中英

Coordinates in landscape mode iPad app correspond to portrait mode

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!

You should use the view's bounds, instead of frame, and you should not execute your code too early in the view's life cycle.

If you invoke your code from the control's viewDidAppear , then I guess it will work. But if you invoke your code from viewWillAppear , then it is too early.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM