UIScreen applicationFrame returns an incorrect rectangle when starting a landscape application (iPhone / iPad)

I can’t get the correct grades for my iPad app when it starts in landscape mode. I have the appropriate keys installed in my Info.plist file, and my view managers run correctly in landscape orientation (and portrait, overnight).

In my applicationDidFinishLaunching: method applicationDidFinishLaunching: I call the selector after a 3 second delay, and this method calls the [[UIScreen mainScreen] applicationFrame] call, but returns me a portrait frame (for example, height> width).

Does anyone know how to fix this? It smells like a mistake for me (if I do the radar), but if it is intended for behavior, where is it documented?

+21
iphone cocoa-touch uikit ipad device-orientation
Apr 19 '10 at 2:58
source share
8 answers

When you hold the iPad in landscape orientation and launch the application, the view controller first sees the borders for the portrait view (even though the orientation is a landscape). Then, the view manager will receive a message to rotate to landscape orientation until it appears.

+6
Apr 19 '10 at 20:59
source share

I never rely on [[UIScreen mainScreen] applicationFrame] , especially during application startup.

When creating views in code, use the supervisor to set the frame.

If you use xibs with "simulated interface elements", they will be the right size and everything will work fine.

UINavigationController Based Applications

In the case of a UINavigationController based application, capture the frame directly from self.navigationController.view , do not try to use [self loadView] and self.view.superview . The UINavigationController uses “hidden” routines to accomplish this task - therefore, direct browsing will not work.

The UINavigationController is special because during the launch of the application, the navigation controller resizes your views after calling loadView . When autoresistant strokes in you end with a small margin at the bottom of the screen.

Why not UIScreen

[[UIScreen mainScreen] applicationFrame] does not work reliably (especially when running the application in the landscape). My experience is that the viewcontroller interfaceOrientation property will not match the orientation of the applicationFrame .

+35
Oct 29 2018-10-29
source share
 CGRect bounds = [[UIScreen mainScreen] bounds]; // portrait bounds if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { bounds.size = CGSizeMake(bounds.size.height, bounds.size.width); } 
+14
Feb 11 '13 at 9:52
source share

So I get the correct CGRect when the view controller is on the 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); 
+6
Jan 31 '12 at 23:50
source share

This is just as good. You must request the size of your supervisor and adjust if necessary.

+5
Apr 19 '10 at 4:22
source share

[[UIScreen mainScreen] applicationFrame] will always return a portrait rectangle, even if the application is in landscape mode. This is because UIWindow never rotates, but simply changes the transformation of rootViewController.view .

To make sure, you can print the root view object in portrait and landscape modes and you will see something like this:

Portrait:

 <UIView: 0x96290e0; frame = (0 20; 768 1004); ... 

Scenery:

 <UIView: 0x96290e0; frame = (0 20; 768 1004); transform = [0, 1, -1, 0, 0, 0]; ... 
+2
Jun 15 '13 at 21:13
source share

So, add a launch image and give it a suffix of -568h, according to Apple guidelines.

I don’t understand why someone with a healthy mind will make the system configuration dependent on the schedule; but I just tested and it worked.

Here is the place that taught me after a quick search I did not see this answer above, I thought that it would be useful to someone.

S

+1
Jun 15 '13 at 20:20
source share

I had the same problem when you rejected a view using rejectViewControllerAnimated in the Cordoba plugin. I changed the singingAtom code for the viewWillAppear method in the MainViewController, which resized after the modal view was rejected:

 - (void)viewWillAppear:(BOOL)animated { CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; UIDeviceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (UIDeviceOrientationLandscapeLeft == orientation || UIDeviceOrientationLandscapeRight == orientation) { if (appFrame.size.width < appFrame.size.height) { appFrame = CGRectMake(appFrame.origin.y, appFrame.origin.x, appFrame.size.height, appFrame.size.width); } } self.view.frame = appFrame; [super viewWillAppear:animated]; } 
0
Oct 11
source share



All Articles