开发者

How to : autorotation on iPad and portrait only on iPhone?

Hi I have just started iPhone programming. I created a universal app for iPad and iPhone in Xcode 3.2 and evrerything is working fine. But now I want to implement following feature in that app:

It should support autorotation on iPad and be portrait only on iPhone.

I have no idea how to do that.

I have an AppDelegate_iPad delegate file, an AppDelegate_iPhone delegate file, and a vi开发者_开发百科ewcontroller under Shared tab and is share by both of these delegates.

Any ideas how can I implement that feature. any help would be appreciated.

Thanks Vik


In the view controller(s) for the view(s) where you want to implement this rotation behavior, do the check inside the shouldAutorotateToInterfaceOrientation, like this:

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {     
    UIDevice* thisDevice = [UIDevice currentDevice];
    if (thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        return true;
    }
    else
    {
        return interfaceOrientation == UIDeviceOrientationPortrait;
    }
}


Apps running iOS 6+ will also want to implement ViewController's:

- (NSInteger)supportedInterfaceOrientations

and/or AppDelegate's:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

E.g.,

- (NSInteger)supportedInterfaceOrientations
{
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜