0

Im quite new to XCode and Interface Builder, so forgive me if the solution is obvious.

I have designed a nice portrait IPhone view in interface builder (XCode 5) and have set the constraints on each of the elements (labels, text views, switches, buttons etc) so that they are positioned correctly in either 3.5 or 4 inch portait mode in the simulator.

However, when I rotate the simulator to landscape it breaks the design with elements overlaying each other and other elements disappearing (being clipped from the view) - and I expected this.

My idea of a solution is to put all of the UI elements inside a UIScrollView and set constraints on the scroll view so that it fills the screen in either portait of landscape mode.

After doing this, the portrait view is as before in the simulator, but in landscape view nothing scrolls, and none of my UI elements respect their constraints (stretch horizontally etc). Im still losing UI at the bottom and I cant scroll it into view.

I assumed that putting everything into the scroll view would simply 'fix' this issue, but the scroll view seems to do absolutely nothing at all. I have fiddled with various settings in interface builder but nothing fixes this.

There seem to be lots of long-winded solutions to this type of scenario based on code, but surely something this simple and common should just 'work'

What am I missing, or what have I done wrong, or does simple scrolling really have to be extensively coded in order to work ???

4

2 回答 2

0

Putting all of your elements inside a scroll view won't really solve anything. Those elements would still need constraints to know how to position themselves in the scroll view. You need to be careful as well, as this solution sounds like something that goes against apples human interface guidelines. I'd advise against ignoring those, as Apple are known to reject apps that do this.

I'd say your problem is your constraints simply aren't setup correctly if elements are cover other elements and moving into the wrong places when rotated.

Annoyingly the WWDC videos section of the developer site is still down, but when it's back up, have a watch of the video of autolayout in Xcode 5, it will help explain what's going on.

If you want elements to completely change position when rotated however, you're likely to need more than just constraints, and would need to throw in some code to handle the transition between portrait and landscape. So it really depends on what the view is supposed to do when you rotate the device

于 2013-07-30T08:37:45.737 回答
0

好的,我想通了。这是XCode 5 或 IOS 7 中的错误

我在界面构建器中创建了 2 个简单的 iphone UI——一个在 Xcode 4.6.3 中针对 IOS 6.1,另一个在 XCode 5 Beta 4 中针对 IOS 7 beta 4。

第一个应用程序完全按照我的假设运行,滚动视图以横向模式滚动。第二个应用程序在滚动视图中根本没有滚动 - 所以显然是一个错误。

于 2013-07-30T19:23:31.893 回答