简体   繁体   English

宽度和高度无法通过Xcode自动布局进行调整

[英]Width and height not adjusting with Xcode Auto Layout

I have created an interface for my app in Storyboard under the Any x Any layout setup, when I run my app the layout is still sized for the square Any x Any and not the phone screen. 我在Storyboard中的Any x Any布局设置下为我的应用程序创建了一个界面,当我运行我的应用程序时,布局的大小仍为正方形Any x Any而不是电话屏幕。 I want the app to adjust to all sizes and not use a set layout for set screen sizes. 我希望该应用程序调整为所有尺寸,而不是为设置的屏幕尺寸使用设置的布局。 How can I do this? 我怎样才能做到这一点?

Here are pictures to show my design, and the outcome of running the app. 这些图片展示了我的设计以及运行该应用程序的结果。

Storyboard View 故事板视图

Simulator View 模拟器视图

The table view is also cut off here 表格视图也在此处被切断

what exactly are you trying to achieve? 您到底想达到什么目的? Your tableview to be entirely on the screen, so not scrollable? 您的表格视图将完全显示在屏幕上,因此无法滚动?

If so, then you should override the layout of your tableview and its corresponding cells. 如果是这样,那么您应该覆盖表格视图及其对应单元格的布局。 As those cells (and the number of them) define the height of your tableview. 这些单元格(及其数量)定义了表格视图的高度。

From what I can see it appears that you have manually added a UINavigationBar. 从我所看到的看来,您已经手动添加了一个UINavigationBar。 I personally find it much easier to embed your view controller into a navigation controller. 我个人发现将视图控制器嵌入导航控制器要容易得多。 This will provide you with a navigation bar that will automatically resize depending on the hardware, or size class, of the device. 这将为您提供一个导航栏,该导航栏将根据设备的硬件或大小类别自动调整大小。 To embed it go to: Editor -> Embed in -> Navigation Controller. 要嵌入它,请转到:编辑器->嵌入->导航控制器。

Your TableView seems to be fully in the screen as well? 您的TableView似乎也完全显示在屏幕上? If you have layout issues with your cells not adjusting then I will be more than happy to help you once you clarify what is not quite right. 如果您的单元无法调整时存在布局问题,那么一旦您弄清了不正确的地方,我们将非常乐意为您提供帮助。

Hope this helps. 希望这可以帮助。

If your ViewController is subclass of UIViewController then add leading, trailing ,top and bottom constraints to UITableView , and contains to your custom navigation bar. 如果您的ViewController是UIViewController子类,则向UITableView添加前导,尾随,顶部和底部约束,并将其包含到自定义导航栏中。 or If its subclass of UITableViewController . 或如果UITableViewController子类。 No need to add any constraints. 无需添加任何约束。 Just embed your TableViewController into NavigationController . 只需将TableViewController嵌入NavigationController

Hope this will help you 希望这个能对您有所帮助

Yep. 是的 Been there, done that. 去过也做过。 Just because something is centered in the Any x Any view in interface builder does not mean it will also be centered eg in an iPhone simulator. 仅仅因为某些东西位于界面构建器中的Any x Any视图的中心,并不意味着它也将位于iPhone模拟器中。 You always need to make your layout choices explicit with constraints, ie in the this case add a "center horizontally in superview" constraint or align the right and left edge with the superview (I really would need to know more about your view controller in interface builder to tell you exactly). 您总是需要通过约束使布局选择明确,例如,在这种情况下,添加“在超级视图中水平居中”约束或将右边缘和左边缘与超级视图对齐(我真的需要在界面中了解更多关于视图控制器的信息。生成器以准确地告诉您)。

Are you familiar with constraints or should I add some more detail on how to solve this? 您是否熟悉约束条件,或者我应该添加更多有关如何解决此问题的详细信息?

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

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