对于iphone 4/4S和iphone 5/5s/5c,我有两种不同的看法。我需要显示正确的视图取决于手机的型号。请有人告诉我,你如何编码这个应用程序,以检查手机型号,然后显示3.5或4英寸的视图?非常感谢!
发布于 2014-04-17 09:20:37
我在我的应用程序中创建了一个宏,并通过它来检查设备:
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )使用它的方式如下:
if (IS_IPHONE_5) {
//iPhone 5x specific code
} else {
//iPhone 4x specific code
}备注:我的部署目标仅是iPhone,没有其他iOS设备,所以代码是安全的,除非未来版本的iPhone有其他维度。
发布于 2014-04-17 09:16:09
您可以将类别写入UIDevice以检查设备屏幕高度:
// UIDevice+Utils.h
@interface UIDevice (Utils)
@property (nonatomic, readonly) BOOL isIPhone5x;
@end
// UIDevice+Utils.m
@implementation UIDevice (Utils)
@dynamic isIPhone5x;
- (BOOL)isIPhone5x {
BOOL isIPhone5x = NO;
static CGFloat const kIPhone5Height = 568;
if (self.userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
CGRect screenBounds = [UIScreen mainScreen].bounds;
if (screenBounds.size.width == kIPhone5Height || screenBounds.size.height == kIPhone5Height) {
isIPhone5x = YES;
}
}
return isIPhone5x;
}
@end
// Usage
if ([UIDevice currentDevice].isIPhone5x) {
// Use 4 inch view here
} else {
// Use 3.5 inch view herehttps://stackoverflow.com/questions/23128699
复制相似问题