iphone - 是否可以创建一半仅与 iphone 兼容而其他部分通用的应用程序?

标签 iphone ios ipad

我正在开发一个应用程序,根据客户的要求,很少有 View 仅与 iPhone 4 设备兼容,而其他 View 与 iPhone 4,5/iPad 兼容。那么单机可以吗?

我知道这是不可能的,但我想要你的建议。
如果您有任何与此相关的链接,请与我分享。

最佳答案

是的,iPhone 3.5"、iPhone 4"和 iPad 可以有不同的 View 。此外,您可以在每个不同的设备中实现不同的功能。但是,iOS User Interface Guidelines建议您在不同的设备上提供相同的功能。

Preserve the primary functionality of your app, regardless of the device it runs on. Even though one version might offer a more in-depth or interactive presentation of the task than the other, it’s important to avoid making users feel that they’re choosing between two entirely different apps.



在实践中,您可以使用以下宏以编程方式编写 fork 来构建(以编程方式) View :
#define isIpad() \
([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && \
[[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad)

#define isWidescreen ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 )<DBL_EPSILON )
#define isIphone ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPhone" ] )
#define isIpod   ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPod touch" ] )
#define isIphone5 ( isIphone && isWidescreen )

此外,您可以使用 fork 和 UIViewController 消息为每个不同的设备创建不同的 xib 文件:- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil , 加载正确的文件。

最后,您可以在 xib 文件名中使用修饰符来加载 iphone 和 ipad 之间的不同资源。例如:您的 iPad UI 有 FirstViewController.xib;如果设备是 iPhone(而不是 FirstViewController.xib),您可以创建一个将由 iOS 自动加载的 FirstViewController~iphone.xib。您可以查看this回答有关此主题的更多信息。

编辑

如果您已经有“仅 iPhone 的 xib 文件”并且您想在 iPad 上运行这些文件,您应该考虑复制每个文件,并将副本转换为 iPad 目标为 thisthis答案解释。然后,您可以重新命名以“~ipad.xib”结尾的副本,这应该可以解决您的问题,但是,此 View 需要修改布局。

关于iphone - 是否可以创建一半仅与 iphone 兼容而其他部分通用的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16775224/

相关文章:

iphone - presentModalViewController - ViewController 在呈现后自动消失

iphone - 我们可以检索当前在 iPhone 和 iPad 中运行的应用程序吗

iphone - 如何从 iPhone 的资源文件夹中获取文件夹和文件列表?

ios - 在 iPad 上 : UITableView's separator between header and cells

objective-c - 如何旋转 UIImage

iphone - 在 IOS 5 中检测设备是否处于静音模式?

c# - MvxTableViewCell 加载一个空 View

ios - 检查日历上是否存在事件

ios - 第一次运行时从 NSUserDefaults 将图像作为 NSData 加载失败

iphone - 如何在iPhone上指定具有不同左右大写尺寸的可拉伸(stretch)图像