开发者

Is repositioning objects with CGRectMake cross-model safe?

If I reposition controls after a device rotation with CGRectMake using the dimensions of an iPhone 3's screen resolution, what can I expect to happen on an iPhone 4 since its reso开发者_Python百科lution is doubled?

For example if I set a button to a size of 125x125 at a position of 20, 20, on an iPhone 4 will it be doubled to 250x250 at 40, 40?

button1.frame = CGRectMake(125,125,20,20);


Yes, doing that is safe. As of iOS 4, there is a built in multiplier in the SDK. Therefore, both the iPhone 2G-3GS's screens and the iPhone 4's screen are laid out on a 320x480 grid. When your code is run on the older devices, the multiplier will be 1, and your controls will appear at (125,125) and will have a size of 20x20 pixels. But, on the iPhone 4, the multiplier will be 2, so your control will show up at (250,250), and be 40x40 pixels. In this way, your UI will look identical on all iOS devices.


For starters, I hope you are using CGRectMake not CGMakeRect. You can position controls without thinking about the resolution of iPhone. You just put frame as if you are targeting only lower resolution devices. But you have to take 2x images of all the images you are using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜