Question

I've had this issue many many times and just can't figure out a solution to it...

Most of our apps run in Landscape mode only, and the app I'm working on now (and many that I've worked on in the past) is displaying the following behavior - on first launch, the app appears properly in Landscape, but any buttons on the right side of the screen cannot be pressed. The app is behaving as if it only recognizes touches on the section of the screen that would be visible if the app was in Portrait mode, disregarding any touches on the right side of the screen. If I click to another viewController and then back to the problematic viewController, it reacts properly to all touches on the screen. Only on first launch does the app think it is running in Portrait and fails to recognize touches to the right of the 768x1024 area (or 1536x2048 or 320x480 or 640x960)

So I am seeing a visual area of 1024x768, but can only click on buttons in the first 768 pixels of the screen (the right-most 256 pixels are inaccessible)

A workaround I've tried (with limited success - it has worked before but doesn't always work and isn't working now) has been including these lines in multiple places such as the AppDelegate.m, in the rootViewController.m, and in the specific viewController.m that is having the issue described above:

self.view.frame = CGRectMake(0.0, 0.0, 1024.0, 768.0);

//I've also tried:

CGRect landFrame = self.view.frame;
landFrame.size.width = self.view.frame.size.height;
landFrame.size.height = self.view.frame.size.width;
self.view.frame = landFrame;

ANY IDEAS?


The .plist values include:

Initial Interface Orientation - Landscape (right home button)

Supported Interface Orientations:

  • Item 0 - Landscape (right home button)
  • Item 1 - Landscape (left home button)

I've got this code in the rootViewController and the specific viewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (UIInterfaceOrientationIsLandscape(interfaceOrientation));

    //I've also tried:
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Était-ce utile?

La solution

This is the most helpful thing I've found:

In app delegate didFinishLaunchingWithOptions:

Change [window addSubview:navigationController.view];

To [window setRootViewController:navigationController];

and in the Root ViewController, change

– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

to:

  • (BOOL)shouldAutorotate {

return YES;

}

and set the Supported Interface Orientations in the .plist file

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top