UIScreen applicationFrame returning incorrect rect

2020-02-03 05:35发布

Having trouble getting the correct bounds for my iPad application when launching it in landscape mode. I have the proper keys set in my Info.plist file, and my view controllers launch properly in landscape (and portrait, natch).

In my applicationDidFinishLaunching: method I'm calling a selector after a 3 second delay, and that method makes a call to [[UIScreen mainScreen] applicationFrame], but it's returning me a portrait frame (ie height > width).

Does anyone know how to fix this? It smells like a bug to me (if so I'll file a radar), but if it's intended behaviour, where is it documented?

8条回答
祖国的老花朵
2楼-- · 2020-02-03 06:22

So, add a launch image and give it the suffix -568h, according to Apple's guides.

I don't understand why anyone with a sound mind would make a system setting depend on a graphic; but I just tested and it worked.

Here is the spot that taught me after a quick search I didn't see this answer above, figured it'd be useful to someone.

S

查看更多
够拽才男人
3楼-- · 2020-02-03 06:25

This is the way I get the correct CGRect when the view controller is on landscape:

CGRect landscapeBounds;
if (self.view.frame.size.width < self.view.frame.size.height)
    landscapeBounds = CGRectMake(self.view.frame.origin.y, self.view.frame.origin.x, self.view.frame.size.height, self.view.frame.size.width);
else
    landscapeBounds = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
查看更多
登录 后发表回答