【发布时间】:2011-04-11 03:43:49
【问题描述】:
我正在尝试将 iPhone 应用程序转换为 iPad。棘手的事情是 iPhone 应用程序必须锁定为纵向视图,而 iPad 应用程序必须锁定为横向视图。我是界面构建器的菜鸟,所以我有点迷茫。
非常感谢任何帮助。谢谢!
【问题讨论】:
标签: iphone interface-builder ipad
我正在尝试将 iPhone 应用程序转换为 iPad。棘手的事情是 iPhone 应用程序必须锁定为纵向视图,而 iPad 应用程序必须锁定为横向视图。我是界面构建器的菜鸟,所以我有点迷茫。
非常感谢任何帮助。谢谢!
【问题讨论】:
标签: iphone interface-builder ipad
您需要覆盖shouldAutorotateToInterfaceOrientation。放置它的好地方是应用程序委托。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
return YES;
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
return YES;
}
return NO;
}
我不确定,但这也可能支持手机倒置,这是一个 HIG no no。您可能希望使用interfaceOrientation == UIInterfaceOrientationPortrait 代替电话。
【讨论】:
UI_USER_INTERFACE_IDIOM()吗?
UIUserInterfaceIdiomPad 没有为 3.x 设备定义
您应该有两个 nib,并根据您的应用程序确定运行在哪个设备上分别加载它们:一个用于 iPad,一个用于 iPhone。然后,您可以轻松设置方向。注意:iPad 应用程序应支持所有方向变体(即,如果您支持纵向,则支持纵向倒置)并且很可能会被 Apple 拒绝,除非您有令人信服的理由说明为什么不应该这样做。
【讨论】: