我知道iPhone 5的尺寸是640 * 960和iPhone 4和以前的iPhone尺寸是320 * 480。现在,我很困惑。如果我想让我的应用程序在这些不同的iPhone上工作,如何计算图像视图或按钮的帧。例如在viewDidLoad中,我有一个图像,它的大小为630 * 100,名称为[email protected],另一个大小为315 * 50,名称为someImage.png。图像是相同的,但大小是不同的。然后我创建了一个带有CGRectMake(5,5,315,50)帧的UIImageView,它的尺寸为320 * 480。如果(iphone5)然后用CGRectMake(10,10,630,100)的框架为UIImageView设置另一个框架,我需要做些什么?我必须为这两种尺寸准备两个不同的UIImageView框架吗?上的点CGRectMake为iPhone 5和iPhone 4
回答
iOS上使用点,而不是所有的像素坐标和大小。正常iPhone屏幕上的1点(320x480)等于1像素。 Retina iPhone屏幕上的1点(640x960)等于2像素。
因此CGRectMake(5, 5, 315, 50)
自动转换为视网膜屏幕上的x = 10,y = 10,宽度= 630,高度= 100。
所以,我只是CGRect为320 * 480大小的矩形,它会自动转换为648 * 960大小的正确值? – 2013-05-08 10:57:22
是的,就是这样。 – 2013-05-08 11:00:21
谢谢。这就是我从一开始就在做的事情,但我很困惑。我认为最好问问你们,所以我可以继续这样做。 – 2013-05-08 11:15:10
的CGRect工作不是像素所以在iPhone4和iPhone5的
没有宽度diffrence如果你使用[[UIScreen mainScreen]applicationFrame].size.width
你得到320宽度的两个设备。
为什么不使用img.size
就像这样:
UIImage *img = [UIImage imageNamed:@"yourImage"];
CGRect * rect = CGRectMake(5, 5, img.size.width,img.size.height);
Uiscrolview *myScrolView= [[Uiscrolview alloc] initWithFrame:CGRectMake(self.view.frame.origin.x+50,self.view.frame.origin.x+50, self.view.frame.size.width-100, self.view.frame.size.height-300);
请解释这是什么。 – 2013-10-11 17:15:45
我永远无法让我的Uiscrolviews正常工作。 – atonyc 2014-06-25 20:25:09
- 1. 做的iPhone 5和iPhone 4
- 2. 图片为iPhone 4和5
- 3. UILabel和UITableView CGrectMake重构 - iPhone
- 4. 将iphone 4应用转换为iphone 5
- 5. UIView Iphone 4和Iphone 5中的问题
- 6. iPhone 5和iPhone 4的屏幕问题
- 7. Iphone 4和iPhone 5的图像
- 8. 微分在iPhone 4,iPhone 5和iPad
- 9. 如何使用Xocde 4.5为iPhone 4和iPhone 5创建xib 4.5
- 10. 在一个应用程序中为iPhone 4和iPhone 5开发
- 11. Kendo ui mobile为iPhone 4和iPhone 5创建动态身高?
- 12. 位置,使为iPhone 4和iPhone兼容5
- 13. 支持iPhone 3G,iPhone 4和iPhone 5的图像分辨率
- 14. iPhone 4应用程序显示为支持iPhone 5而不支持iPhone 4
- 15. 响应式菜单(iphone 4到iphone 5)
- 16. 从iPhone 5+压缩iPhone 4/4s的UI
- 17. 检测并为iPhone 3和iPhone 4
- 18. MonoTouch:为iPhone 5添加[email protected] Retina 4
- 19. Xcode iPhone 4/5屏幕尺寸均为
- 20. iphone 5和4的故事板布局
- 21. 无法为iPhone 5和iPhone5s
- 22. 更新iPhone 5的旧应用程序或如何为iPhone 5和iPhone 4创建应用程序
- 23. Xcode为iPhone 4调整iPhone 5应用程序的大小
- 24. 将应用程序从iPhone 5转换为iPhone 4设备
- 25. 如何修复我的[UIScreen mainscreen]将iPhone 5识别为iPhone 4
- 26. 自动布局是否适合iPhone 5和iPhone 4的背景?
- 27. 在iphone 4和iphone 5模拟器上不能缩放图像
- 28. 使媒体查询兼容iPhone 4和iPhone 5
- 29. 中心对齐在两个iPhone 5和iPhone 4
- 30. 兼容性问题的iPhone 4和iPhone 5
不,但这已被问了很多很多次。 CoreGraphics使用点,而不是像素。 – 2013-05-08 10:19:16
那么我如何设置点,当我只有像素的大小? – 2013-05-08 10:59:16
你不会对尺寸有任何顾忌,CG会自动为你解决问题。但是这已经被很多次的回答了。 – 2013-05-08 11:06:56