xcode 什么是自动布局?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12424248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:29:48  来源:igfitidea点击:

What is Auto Layout?

iphoneiosxcodecocoa-touchautolayout

提问by Devfly

What is Auto Layout - what does it do, and is it an iOS 5 feature?

什么是自动布局 - 它有什么作用,它是 iOS 5 的一项功能吗?

Since the new iPhone 5 has a bigger screen, all the options on how to optimize your applications for it come down to Auto Layout.

由于新的 iPhone 5 有更大的屏幕,所有关于如何优化应用程序的选项都归结为自动布局。

Can you point me to some article about Auto Layout, and how I can adapt it with my project?

你能指点我一些关于自动布局的文章,以及我如何在我的项目中调整它?

回答by DrummerB

I recommend watching the WWDC 2012 session Introduction to Auto Layout for iOS and OS X.

我建议观看 WWDC 2012 会议“iOS 和 OS X 自动布局简介”

Auto Layoutis a new way to define dynamic GUIs. Before, we had autoresizing masks, that described how a subview will resize or move when its superview is resized. With Auto Layout you can do the same and also a lot more complicated GUIs quite easily.

自动布局是一种定义动态 GUI 的新方法。之前,我们有自动调整大小蒙版,它描述了子视图在其父视图调整大小时如何调整大小或移动。使用自动布局,您可以很容易地做同样的事情,也可以做更复杂的 GUI。

回答by David Raijmakers

https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AutolayoutPG/Articles/Introduction.html

https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AutolayoutPG/Articles/Introduction.html

"If Auto Layout in iOS 6 turns out to be anything like Cocoa Auto Layout in Mac OSX 10.7, the Cocoa Auto Layout Guide, a publicly available document, may give you an idea of how it would work in Cocoa Touch.

“如果 iOS 6 中的 Auto Layout 与 Mac OSX 10.7 中的 Cocoa Auto Layout 类似,那么 Cocoa Auto Layout Guide(公开可用的文档)可能会让您了解它在 Cocoa Touch 中的工作方式。

The underlying engine used by Cocoa Touch is Cassowary, and it's also used in other toolkits, such as enaml. I recently wrote a brief overview of Cassowary, with a comparison between Cocoa Touch and enaml wherein I port a Cocoa Auto Layout example to Python and enaml."

Cocoa Touch 使用的底层引擎是 Cassowary,它也用于其他工具包,例如 enaml。我最近写了一篇关于 Cassowary 的简要概述,比较了 Cocoa Touch 和 enaml,其中我将 Cocoa 自动布局示例移植到 Python 和 enaml。”

From: https://stackoverflow.com/a/11129597/1648976

来自:https: //stackoverflow.com/a/11129597/1648976

And the WWDC Session: https://developer.apple.com/videos/wwdc/2012/?id=202

和 WWDC 会议:https: //developer.apple.com/videos/wwdc/2012/?id =202

回答by Bourne

iOS 6 is still under NDA. Hold out for a few more days. It is an iOS 6> feature. In case you have a developer account, you must be already able to learn about Auto Layout from the documentation or from the WWDC 2012 session videos.

iOS 6 仍处于保密协议之下。再坚持几天。这是一个 iOS 6> 功能。如果您有开发者帐户,您必须已经能够从文档或 WWDC 2012 会议视频中了解自动布局。

回答by Pritesh Patel

"Autolayout" is used to adapt layout to different screen size,orientation and localisation.

“自动布局”用于使布局适应不同的屏幕尺寸、方向和定位。

In Autolayout we don't give input based on "x" and "y" coordinate (old style). Instead we define the layout using mathematical relationship between the elements in our view. We can define this relationship using constraints or individual elements or constraint between a set of elements. Once we redefine the layout using this relationship .Our app can adapt to different layout based not only on device size like 5 inch or 5.5 inch in iPhone, but orientation and localisation as well.

在自动布局中,我们不会根据“x”和“y”坐标(旧样式)提供输入。相反,我们使用视图中元素之间的数学关系来定义布局。我们可以使用约束或单个元素或一组元素之间的约束来定义这种关系。一旦我们使用这种关系重新定义布局。我们的应用程序不仅可以根据设备尺寸(如 iPhone 中的 5 英寸或 5.5 英寸)来适应不同的布局,还可以根据方向和本地化进行调整。

For further understanding you can visit:http://www.raywenderlich.com/83129/beginning-auto-layout-tutorial-swift-part-1

如需进一步了解,您可以访问:http: //www.raywenderlich.com/83129/beginning-auto-layout-tutorial-swift-part-1

回答by Mr.Javed Multani

What is Auto Layout?

什么是自动布局?

Auto Layout is a constraint-based layout system. It allows developers to create an adaptive interface that responds appropriately to changes in screen size and device orientation. Without using Auto Layout, it would be very hard for you to build an app that supports all screen sizes.

Auto Layout 是一个基于约束的布局系统。它允许开发人员创建自适应界面,以适当响应屏幕尺寸和设备方向的变化。如果不使用自动布局,您将很难构建支持所有屏幕尺寸的应用程序。

enter image description here

在此处输入图片说明

Why Auto Layout?

为什么要自动布局?

Auto Layout is a way that lets developers create user interface by defining relationships between elements. It provides a flexible and powerful system that describes how views and the UI controls relate to each other. By using Auto Layout, you can get an incredible control over layout, with a wide range of customization, and yield the perfect interface.

自动布局是一种让开发人员通过定义元素之间的关系来创建用户界面的方式。它提供了一个灵活而强大的系统来描述视图和 UI 控件如何相互关联。通过使用自动布局,您可以获得令人难以置信的布局控制,具有广泛的自定义,并产生完美的界面。

Auto Layout is compatible with many of Apple's most exciting application programming interfaces (APIs), including animations, motion effects, and sprites.

自动布局与许多 Apple 最令人兴奋的应用程序编程接口 (API) 兼容,包括动画、运动效果和精灵。

enter image description here

在此处输入图片说明

Reference: https://www.appcoda.com/introduction-auto-layout/

参考:https: //www.appcoda.com/introduction-auto-layout/

回答by Manish Methani

UIView Autolayout is a very interesting concept in iOS App development. Autolayout takes care of responsive design. iPhone comes with different screen sizes every time. With the help of Autolayouts, you do not have to create your App design each time. Autolayout takes care of responsive design.

UIView Autolayout 是 iOS App 开发中一个非常有趣的概念。自动布局负责响应式设计。iPhone 每次都有不同的屏幕尺寸。在 Autolayouts 的帮助下,您不必每次都创建应用程序设计。自动布局负责响应式设计。

This article on "Introduction to Autolayouts"will give you enough understanding about it.

这篇关于“Autolayouts 简介”的文章会让你对它有足够的了解。