我想将我的应用更新到iOS 6,那么如何设置框架大小以适应iPhone 4和iPhone 5的屏幕?
+(CGFloat)heightOf:(CGFloat)heightValue{
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
//NSLog(@"applciation Frame height = %f",applicationFrame.size.height);
CGFloat heightRatio = (heightValue/480)*100;
CGFloat height = (applicationFrame.size.height * heightRatio)/100;
return height;
然后我使用类似于以下的方式:
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,[Height heightOf:385], 320, 220)];
那么,感谢您的回复。
处理这种情况有多种方法。
1> 其中一个方法是正确使用自动调整大小。
2>另一种方法是使用新的自动布局功能,但这只支持iOS 6。
3>您可以为每个视图创建单独的nib文件,一个用于iphone 4,另一个用于iphone 5,并根据运行的设备切换所使用的.xib文件。
目前最好的方法是正确使用自动调整大小。
更多信息,请参见以下内容
#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define IS_IPOD ( [[[UIDevice currentDevice ] model] isEqualToString:@"iPod touch"] )
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )
AutoLayout 对我来说效果不太好。我的应用程序有几个元素需要均匀间隔。
一个快速解决方案(不是很好的做法)是在屏幕高度检查时单独分配坐标。 (顺便说一句,那是一个很好的教程。可惜苹果还没有为 IOS 提供实质性的东西)。
如果您的屏幕上有多个元素,则我认为您将不得不逐个重新放置它们。
CGFloat height = [UIscreen mainScreen].bounds.size.height;
if(height==568.00){
self.imageName.frame = CGRectMake(x,y,width,height);
...
}
self.imgBadgeArea.frame = CGRectMake(self.view.bounds.size.width/2- self.imgBadgeArea.bounds.size.width/2, self.view.bounds.size.height/2 - self.imgBadgeArea.bounds.size.height/2, self.imgBadgeArea.bounds.size.width, self.imgBadgeArea.bounds.size.height);
适用于3.5英寸和4英寸设备。