简体   繁体   English

iPhone应用程式大小相容性

[英]iPhone App Size Compatibility

I'm making an iPhone app, and I'm using storyboard for the majority of the UI. 我正在制作iPhone应用程序,并且大部分用户界面都使用情节提要。 I'm using xCode 4.6 for iOS 6. 我正在使用适用于iOS 6的xCode 4.6。

Is there a way to make the app work for both iphone4 size and iphone5 sizes? 有没有办法让该应用程序同时适用于iphone4尺寸和iphone5尺寸?

When I run the app on the iPhone 4 simulator it doesn't look like it's supposed to - the UI elements don't look like they do on the storyboard (which I'm assuming uses the iPhone5 size). 当我在iPhone 4模拟器上运行该应用程序时,它看起来不应该-UI元素看起来像在情节提要板上一样(我假设使用的是iPhone5大小)。

Let me know if you need more info. 让我知道您是否需要更多信息。

You can dynamically access the height of the view and the device, and then make adjustments based on those values. 您可以动态访问视图和设备的高度,然后根据这些值进行调整。 Alternatively, you could use iOS 6's constraints to set a margin between the bottom of the device or between other elements. 另外,您可以使用iOS 6的约束在设备底部或其他元素之间设置边距。

To achieve the former, just access the height property of the view: 要实现前者,只需访问视图的height属性:

CGFloat height = [[self view] frame].size.height;

You can also get the height of the device's screen like so: 您还可以像这样获取设备屏幕的高度:

CGFloat deviceHeight = [[UIScreen mainScreen] bounds].size.height;
deviceHeight -= 20; // remove the tab bar
deviceHeight -= 44; // remove height for a navigation bar?

Now imagine adjust your view's origin based on this value. 现在,假设根据此值调整视图的原点。 You can make it hug the bottom of the device, no matter which one you're on. 无论使用哪种设备,都可以使它紧靠设备的底部。

[aView setFrame:CGRectMake(10, deviceHeight - 10 - 100, 300, 100)];

If you're unable to adjust the layout of the elements, consider using a scroll view as well. 如果您无法调整元素的布局,请考虑同时使用滚动视图。 Just set the frame using the techniques above, and then set the content size. 只需使用上述技术设置框架,然后设置内容大小即可。 On smaller devices, you'll be able to scroll to see more content whereas on larger devices, it will all be right there. 在较小的设备上,您将可以滚动查看更多内容,而在较大的设备上,一切都将在那里。

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

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