如何在ios6中设置iphone 4和iphone 5的帧

时间:2012-10-10 07:19:46

标签: iphone uiview ios6 frame

我想将我的应用程序更新到ios 6.那么如何设置iphone 4和iphone 5的框架尺寸?

5 个答案:

答案 0 :(得分:4)

我可以使用“计算屏幕大小”来调整视图的高度,就像使用以下方法

一样
+(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 :(得分:3)

处理这种情况的方法不止一种。

1>其中之一是正确使用自动调整大小。

2>另一种方法是使用新的自动布局功能,但是再次只支持iOS 6。

3>您可以为iphone 4和iphone 5的每个视图创建单独的笔尖,并且根据它运行的设备,您可以切换使用过的.xib文件。

现在最好的方法是使用,正确自动调整大小。

您可以通过这些

获取更多信息

1> Supporting iOS 4.3 to iOS 6.0

2 - ; What is the best way for supporting both screen resolution of iPhone4 and iPhone5 ? - Auto layout in only iOS6

答案 2 :(得分:1)

以下代码检查iPhone 5和其他设备

#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 )

And check for more detail refer the question.

答案 3 :(得分:0)

您可以检查设备类型link,或者您可以检查iPhone 4 / 4s中的视图框架是否大于正常视图框架然后调整框架大小

注意:我使用第二种方式,这是工作

答案 4 :(得分:0)

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英寸。