简体   繁体   English

如何从iPAD / iPAD2布局转换为iPhone4 / iPhone5 / iPAD-mini布局

[英]How to convert from iPAD/iPAD2 layout to iPhone4/iPhone5/iPAD-mini layout

I never used Interface Builder ever in my app, and don't think it is something good to do. 我从来没有在我的应用程序中使用过Interface Builder ,也不认为这是一件好事。

My app was already designed for iPad/iPad2 layout, without ever considering making it work on iPhone4/iPhone5/iPAD-mini. 我的应用程序已经针对iPad / iPad2布局设计,而没有考虑使其能够在iPhone4 / iPhone5 / iPAD-mini上运行。 Now I want my app to work on all of them. 现在,我希望我的应用程序可以在所有这些应用程序上运行。

I think it would be extremely ugly to have 4+ layout the universal app, like this: 我认为拥有4种以上通用应用程序布局会非常丑陋,如下所示:

if(ipad or ipad2) 
 view.frame = CGRectMake(0,0,100,100);
else if(ipad-mini)
  view.frame = CGRectMake(0,0,100,100);
else if(iphone4)
  view.frame = CGRectMake(0,0,100,100);
else if(iphone5)
  view.frame = CGRectMake(0,0,100,100);
else if(iphone6)
  view.frame = CGRectMake(0,0,100,100);
else if(iphone7)
  view.frame = CGRectMake(0,0,100,100);

There should be only 2 layout ideally, but I don't know how to implement this way. 理想情况下应该只有2个布局,但是我不知道如何实现这种方式。 Those fixed coordinates would not stretch on different screen sizes 那些固定的坐标不会在不同的屏幕尺寸上拉伸

if(ipad or ipad2 or ipad-mini) 
  view.frame = CGRectMake(0,0,100,100);
else if(iphone4 or iphone5 or iphone6 or iphone7)
  view.frame = CGRectMake(0,0,100,100);

How do I do a universal app in the best way? 如何以最佳方式制作通用应用程序?

when you started building this app you should have done soemthing like this: 当您开始构建此应用时,您应该已经完成​​了以下工作:

 view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;

and you change above options according to your needs. 然后您可以根据需要更改上述选项。

and yes you would need different for ipad, iphone 是的,您将需要为iPad,iPhone提供不同的服务

First of all, your layout for iPhone will almost certainly be drastically different from iPad. 首先,iPhone的布局几乎肯定会与iPad完全不同。 For the iPads, all the different types have the same aspect ratio, so all you need to worry about is having the @2x images for the iPad with retina. 对于iPad,所有不同类型的宽高比都相同,因此您只需担心带视网膜的iPad具有@ 2x图像。

For the iPhone, however, you have the iPhone 4/4s VS the iPhone 5. Also, you have a lot less screen space, so you will need to find ways to present the same information in a smaller space. 但是,对于iPhone,您拥有iPhone 4 / 4s VS iPhone5。此外,您的屏幕空间要少得多,因此您将需要找到在较小的空间中显示相同信息的方法。 This can be done using scrollviews, tableViews, and having one part of the information in one viewController that you can switch to from another viewController. 可以使用scrollviews,tableViews并将信息的一部分包含在一个viewController中,您可以从另一个viewController切换到其中。

Finally, I would highly recommend interface builder for most cases. 最后,我强烈建议大多数情况下使用界面构建器。 It takes care of iPhone vs iPhone 5, and portrait vs landscape for you. 它会为您照顾iPhone vs iPhone 5,以及肖像vs风景。 It will even automatically animate the transition when rotating the phone. 旋转手机时,它甚至会自动为过渡设置动画。 Sometimes, however, when you need to do custom drawing or our layout is really hard to get with interface builder, it is better to do it programmatically. 但是,有时候,当您需要自定义图纸或使用界面生成器确实很难获得我们的布局时,最好以编程方式进行。 In that case, a good way to check which device would be by checking the size of [[UIScreen mainScreen] applicationFrame] . 在这种情况下,检查[[UIScreen mainScreen] applicationFrame]的大小是检查哪个设备的好方法。 Check that with the values of 1024x768 for an iPad, 320x480 for iPhone, or 320x568 for iPhone 5. 对于iPad,请检查其值为1024x768,对于iPhone,请检查其值为320x480,对于iPhone 5,请检查其值为320x568。

However, you really should use interface builder (for most cases). 但是,实际上,您应该使用界面生成器(在大多数情况下)。 Why exactly do you want to avoid it? 您为什么要避免这种情况?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM