开发者

Remove ability for portrait orientation for app in iPhone SDK

Is there a way where I can only allow my app viewable in landscape mode? I've managed to default the application's orientation to landscape, however in the iPad simulator, when I do Command->Arrow, the application rotates to portrait. I've removed the listings in the plist under "Supported interface orientations" for both of the Portrait entrie开发者_JAVA技巧s, however that doesn't seem to've changed anything.

Any idea?


In your view controller, there's a delegate method for this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
            (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


Do a project find for "autorotate", and edit the methods you'll find accordingly.


I believe you need tell the view that the specified orientation is not supported

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/shouldAutorotateToInterfaceOrientation:


Actually it is

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


Things have changed with some updates. Currently, you'll simply need to add the following method:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

that will only allow landscape. Turn the phone all you like and it will only stay in either left or right landscape. Have fun :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜