您的通用转换应该毫不费力。您的 iPad 用户会欣赏这项工作。但除非您计划添加一些重大的 UI 更改,否则一定要转换它,在这些更改中重写将是有益的。
在从 iPhone 代码中确定 iPad 代码的简单方法中,使用:
#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
#define IPHONE UIUserInterfaceIdiomPhone
关于上述IDIOM
内容,我看到 Apple 在 iOS 5.1 中使用了以下内容:
[[UIDevice currentDevice] userInterfaceIdiom]
所以你也可以使用
#define IDIOM [[UIDevice currentDevice] userInterfaceIdiom]
例子
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ( IDIOM == IPAD ) {
/* Device is an iPad, so let the interface rotate. */
return YES;
}else{
/* Device is an iPhone / iPod touch, so do not allow the interface rotate. */
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
return YES;
}