简体   繁体   English

Swift-布局问题

[英]Swift - Problems with layout

I have a Universal application in Swift 2.0 developed in XCode 7. 我在XCode 7中开发的Swift 2.0中有一个通用应用程序。

On the storyboard simulated metrics, I have the 'size' set to 'iPhone 4.7-inch'. 在情节提要板上模拟的指标上,我将“大小”设置为“ iPhone 4.7英寸”。

When I run the application on my device (iPhone 5s), none of the labels are aligned and the toolbar is out of view. 当我在设备(iPhone 5s)上运行该应用程序时,所有标签都没有对齐,并且工具栏也不可见。 -This is also the case when I run using the iPad device in XCodes simulator. -在XCodes模拟器中使用iPad设备运行时也是如此。

Image of what the view controller contains ... 视图控制器包含的图像...

在此处输入图片说明

From the snippet above, when I run this VC on my iPhone there is no margin on the right side, and the toolbar is cropped off. 从上面的片段中可以看到,当我在iPhone上运行该VC时,右侧没有空白,并且工具栏也被裁剪掉了。

Can anyone advise how I can make a universal application show all the content in the VC, on all devices. 谁能建议我如何使通用应用程序在所有设备上显示VC中的所有内容。 Or how I would simply show the toolbar ... 或者我只是显示工具栏的方式...

That's what auto layout ( constraints ) is for. 这就是自动布局( 约束 )的目的。

On the storyboard simulated metrics, I have the 'size' set to 'iPhone 4.7-inch'. 在情节提要板上模拟的指标上,我将“大小”设置为“ iPhone 4.7英寸”。

That's irrelevant, and indeed misleading, since in means that only on the iPhone 4.7-inch will your app look like the storyboard design — unless you use auto layout. 这无关紧要,而且确实具有误导性,因为这意味着仅在4.7英寸iPhone上,您的应用程序才会看起来像情节提要设计一样-除非您使用自动布局。

iPhones come in many screen sizes. iPhone有多种屏幕尺寸。 Basically, you have no way of knowing, as you design, what the screen size will actually be! 基本上,您无法在设计时知道屏幕的实际尺寸! Auto layout is the solution. 自动布局是解决方案。 Auto layout allows your interface elements to adjust automatically as the app launches on a particular size screen. 自动布局允许您在应用程序在特定尺寸的屏幕上启动时自动调整界面元素。 iPads can serve as an extension of this — ie, just an even larger size screen — or you can even use conditional constraints to make the interface quite different on the iPad from the iPhone, if desired - all designed in a single storyboard. iPad可以作为此扩展(即,甚至更大的屏幕),或者如果需要,您甚至可以使用条件约束使iPad上的界面与iPhone完全不同,所有界面都在一个故事板上设计。

Maybe you are using auto layout and auto constraint. 也许您正在使用自动布局和自动约束。 You could deactivate this in opening the storyboard, open up right panel , go to "show the file inspector" section and under Interface Builder Document uncheck auto layout and auto constraint 您可以在打开情节提要,打开右侧面板,转到“显示文件检查器”部分并在Interface Builder文档下取消选中自动布局和自动约束,以停用此功能。

Image here 图片在这里

Select your item view, go into "Show the size inspector" and there you can set your autoresizing for all devices 选择项目视图,进入“显示尺寸检查器”,然后可以在其中设置所有设备的自动调整大小

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

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