开发者

iPad stop screen from Rotating Xcode 4

I am building an iPad app in Xcode 4. The app is suposed to always show in Landscape view. to achieve this I have tried the following:

  • In the Target summary screen I selecte only Landscape Left as a Supported Device Orentation.
  • In the Target Info screen / Info.plist set the Supported interface orientations(iPad) to Landscape (left home button)

This leads the app the to start in landscape mode, but if I rotate the device it still changes its orientation. Also, when I have a UIViewController presented with presentationStyle UIPresentationFormSheet it rotates to portrait the moment it shows.

In some other threads / forums it was adviced to create a category for UIViewController and rewrite

-(UIDeviceOrientation)interfaceOrientation;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

To always rotate to the Device Orientation (LandscapeLeft) or specifically LandscapeLeft, also to no AutoRotate unless you rotate to LandscapeLeft.

When I set these functions like this (Or for example allow no rotation at all) the a开发者_如何学Pythonpp always appears in portrait mode, and wont rotate, not even to LandscapeLeft. The only way to have the app start in Landscape mode is when I allow for rotation no matter what the interfaceOrientaton is.

Does anybody know how I can fix this?

The category I implemented:

@implementation UIViewController(Extends)

-(UIDeviceOrientation)interfaceOrientation
{

    return [[UIDevice currentDevice] orientation];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return YES;
    else
        return NO;
}

@end

The only place that I can find a Portrait Orientation to be defined is the original window on the MainWindow.xib, but this cannot be altered, and every thread/forum says that that particular setting is/should not be the issue.


As far as I can tell the steps you took should prevent rotation of the interface.

You can always try to override the calls that do the orientation in every viewcontroller of your app. That should at least give you a clue where the rotation is happening. After which a breakpoint can possibly tell you more.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
   NSLog( @"will rotate to orientation %d in %@", interfaceOrientation, NSStringFromClass([self class])
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
   NSLog( @"did rotate from orientation %d to %d in %@", fromInterfaceOrientation, [self interfaceOrientation], NSStringFromClass([self class])
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜