如何:在iPad上自动旋转和仅在iPhone上纵向显示?
问题描述:
嗨,我刚刚开始iPhone编程。我在Xcode 3.2中为iPad和iPhone创建了一个通用应用程序,evrerything工作正常。但是现在我想在该应用中实现以下功能:如何:在iPad上自动旋转和仅在iPhone上纵向显示?
它应该支持在iPad上自动旋转,并且只能在iPhone上显示人像。
我不知道该怎么做。
我有一个AppDelegate_iPad代表文件, 一个AppDelegate_iPhone代表文件, 和共享选项卡下的ViewController和是这两个代表份额。
任何想法如何实现该功能。任何帮助,将不胜感激。
感谢 维克
答
在为要实现这种旋转行为期(县)的视图控制器(S),做shouldAutorotateToInterfaceOrientation
内的检查,就像这样:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
UIDevice* thisDevice = [UIDevice currentDevice];
if (thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
return true;
}
else
{
return interfaceOrientation == UIDeviceOrientationPortrait;
}
}
答
运行iOS 6+的应用程序也将要实施的ViewController的:
- (NSInteger)supportedInterfaceOrientations
和/或AppDelegate中的:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
例如,
- (NSInteger)supportedInterfaceOrientations
{
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}