简体   繁体   English

Storyboards 和 Interface Builder 之间的关系是什么?

[英]What is the relationship between Storyboards and the Interface Builder?

I just started learning XCode, objective-c, iOS, and all that.我刚开始学习 XCode、objective-c、iOS 等等。 This is my first foray into app development.这是我第一次涉足应用程序开发。 I'm not new to development, just iOS development and XCode.我不是开发新手,只是 iOS 开发和 XCode。

So I'm going through a Udemy course that has me working with storyboards and I have some concern because every professional iOS developer I know uses something called Interface Builder which apparently removes the need for storyboards.因此,我正在学习 Udemy 课程,该课程让我使用情节提要,我有些担心,因为我认识的每个专业 iOS 开发人员都使用一种称为 Interface Builder 的东西,这显然消除了对情节提要的需要。

I've only just started, so I still have only a rough idea of what a storyboard even is....it seems to just be a graphical representation of a single page view.我才刚刚开始,所以对于 storyboard 到底是什么,我仍然只有一个粗略的概念……它似乎只是单个页面视图的图形表示。 I don't know how it relates to this so-called Interface Builder and what their relationship is.我不知道它与这个所谓的Interface Builder有什么关系,它们之间的关系是什么。

By going through this course learning with storyboards, am I being put on the wrong track?通过使用故事板学习本课程,我是否走错了路? Or is this a useful beginning step before transitioning to the Interface Builder?或者这是过渡到 Interface Builder 之前有用的开始步骤吗? Will using storyboards help me to work with that later?使用故事板会帮助我以后处理它吗? Am I wasting my time?我在浪费时间吗?

The Interface Builder refers to the part of Xcode that lets you view and edit Storyboards and .xib files (it automatically opens when you click on such a file). Interface Builder是Xcode的一部分,可让您查看和编辑情节提要和.xib文件(单击此类文件时它会自动打开)。

A .xib (or 'nib') file is a representation of a single logical view in you application (on iOS, typically a UIViewController with a number of views, such as a UIScrollView and a UINavigationBar ). .xib(或“ nib”)文件表示应用程序中的单个逻辑视图(在iOS上,通常是具有多个视图的UIViewController ,例如UIScrollViewUINavigationBar )。

A storyboard is a collection of such views, and can be used to build transitions from views to other views, among other things. 故事板是这些视图的集合,并且可以用于建立从视图到其他视图的过渡。

I recommend reading Apple's Documentation on storyboards to get an idea of what they can do for you. 我建议阅读故事板上的Apple文档 ,以了解它们可以为您做什么。

... ...
Interface Builder which apparently removes the need for storyboards. Interface Builder显然消除了对故事板的需求。
... ...

Actually, storyboard is a concept within Interface Builder. 实际上, 情节提要是Interface Builder中的一个概念。
It's a visual representation of the entire app flow. 它是整个应用程序流程的直观表示。

I think all you need is a quick-read through the Apple Interface Builder Doc . 我认为您所需要的只是快速阅读Apple Interface Builder文档
In basic understanding, IB is a drag-drop area to visually create your views. 在基本的理解上,IB是一个拖放区域,以可视方式创建您的视图。

To quote: 报价:

You create your app's user interface in Interface Builder. 您可以在Interface Builder中创建应用程序的用户界面。 Select a user interface file in the project navigator, and the file's contents open in Interface Builder in the editor area of the workspace window. 在项目导航器中选择一个用户界面文件,然后在工作区窗口的编辑器区域的Interface Builder中打开该文件的内容。 A user interface file has the filename extension .storyboard or .xib. 用户界面文件的文件扩展名为.storyboard或.xib。

Logical Example: Instead of programmatically coding a UIButton and setting it's frame or constraints, you go to the Interface Builder, select a UIButton object and place it where you would want it to go. 逻辑示例:无需以编程方式编码UIButton并设置其框架或约束,而是转到Interface Builder,选择一个UIButton对象,然后将其放置在想要的位置。 You will also specify what the object name and what method it responds to. 您还将指定对象名称及其响应的方法。 ( but this will need the object name and method name to be defined in the respective class's .m or .h file that the view is associated with ) 但这将需要在与视图关联的相应类的.m或.h文件中定义对象名称和方法名称


Interface Builder can be either XIB/nib or Storyboard. Interface Builder可以是XIB / nib或Storyboard。 Latter of which is the more recent ( and recommended ) method provided by Apple. 后一种方法是Apple提供的最新方法( 推荐方法)。

Using a storyboard, you have one single file, a .storyboard file that will represent the entire app flow. 使用情节.storyboard ,您只有一个文件,即.storyboard文件,它将代表整个应用程序流程。
An app can have multiple screens/views and so a storyboard will basically represent multiple UIViewController s, each of which will be tied to a particular class. 一个应用程序可以具有多个屏幕/视图,因此一个故事板将基本上代表多个UIViewController ,每个UIViewController都将绑定到一个特定的类。

For example, in this storyboard, you can visually see ( assumptions from here on ) that you have, say, 5 screens in the entire app: 例如,在此故事板中,您可以直观地看到( 从此处开始的假设 )整个应用中有5个屏幕:

  1. Screen 1 begins with maybe a UINavigationController 屏幕1可能以UINavigationController开头
  2. Screen 2 is the root view of this UINavigationController , say, LoginVC (tied to LoginVC.m and LoginVC.h ) . 屏幕2是此UINavigationController的根视图,例如LoginVC (绑定到LoginVC.mLoginVC.h
    • A button on LoginVC takes you to, say, SignUpVC (tied to SignUpVC.m and SignUpVC.h ) LoginVC上的一个按钮将带您进入SignUpVC (与SignUpVC.mSignUpVC.h
    • Another button on LoginVC takes you to, say, ProfileVC (tied to ProfileVC.m and ProfileVC.h ) LoginVC上的另一个按钮将带您进入ProfileVC (与ProfileVC.mProfileVC.h
  3. Screen 3 is SignUpVC 屏幕3是SignUpVC
    • A button takes you back to LoginVC 单击一个按钮即可回到LoginVC
  4. Screen 4 is ProfileVC 屏幕4是ProfileVC
    • A button takes you to SettingsVC (tied to SettingsVC.m and SettingsVC.h ) 单击一个按钮即可转到SettingsVC (与SettingsVC.mSettingsVC.h绑定)
    • A button logs you out and takes you back to LoginVC 一个按钮将您注销,带您回到LoginVC
  5. Screen 5 is SettingsVC 屏幕5是SettingsVC

Q. Q.

By going through this course learning with storyboards, am I being put on the wrong track? 通过使用情节提要学习本课程,我是否走错了轨道?

A. 一种。
No, absolutely not. 不,绝对不是。 You're going in the right direction. 您朝着正确的方向前进。
However, i think knowing the former XIB/nib method is worth your time as well. 但是,我认为了解以前的XIB / nib方法也值得您花时间。
Plus, programmatically creating UIView s is highly recommended. 另外,强烈建议以编程方式创建UIView


Q. Q.

...is this a useful beginning step before transitioning to the Interface Builder? ...这是过渡到Interface Builder之前有用的开始步骤吗?

A. 一种。
It's already getting you acquainted with the Interface Builder so there won't really be much "transitioning" required. 它已经使您熟悉Interface Builder,因此实际上并不需要太多的“转换”。


Q. Q.

Will using storyboards help me to work with that later? 使用情节提要板可以帮助我以后使用它吗? Am I wasting my time? 我在浪费时间吗?

A. 一种。
Yes, unless you work in a team under version control, in which case, XIB still looks good. 是的,除非您在版本控制下的团队中工作,在这种情况下,XIB仍然看起来不错。


So what's XIB? 那么什么是XIB?

It's still within the Interface Builder scope... 它仍然在Interface Builder范围内...
Break a storyboard into it's individual views and you have multiple files ( .xib files ) that represent a UIView or UIViewController for a single class. 将情节提要分解为单独的视图,您将拥有多个文件( .xib文件 ),它们代表一个类的UIViewUIViewController ( hence helps when you work in a team under version control ) 因此,在版本控制下的团队中工作时会有所帮助

So now... instead of having one .storyboard , you will have multiple .xib files that will be associated to all those classes that ( you deem ) needed a visual representation. 因此,现在……而不是只有一个.storyboard ,您将拥有多个.xib文件,这些文件将与( 您认为 )需要直观表示的所有这些类相关联。


Links: 链接:

Storyboard: Has a nice UI designer, WYSIWYG, drag, resize design editor, that generates code and sync with manual code changes. Storyboard:有一个很好的 UI 设计器,所见即所得,拖动,调整大小的设计编辑器,生成代码并与手动代码更改同步。

SwiftUI: Code is the single source of truth. SwiftUI:代码是唯一的真实来源。 No Designer.没有设计师。 Lots of hard coding大量的硬编码

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

相关问题 使用Interface Builder和故事板构建控制器之间的关系 - Using Interface Builder and storyboards to build relationships between controllers 在Interface Builder中使用Storyboard隐藏导航栏 - Hide Navigation Bar in Interface Builder w/ Storyboards 访问Interface Builder和/或Storyboard中的“文本样式” - Accessing “text styles” in Interface Builder and/or Storyboards 如何使用故事板在界面构建器中连接自定义UIView? - How to connect custom UIView in interface builder using storyboards? Interface Builder会以较小的增量降低故事板,调整视图大小和重新定位视图 - Interface Builder degrades storyboards, resizes and repositions views in small increments Xcode 4 / Interface builder布局问题:两者有什么区别? - Xcode 4/Interface builder layout question: What is the difference between the two? 什么是Interface Builder中的适应 - What is Adaptation in Interface Builder Storyboard中的Modal和Push segue有什么区别? - What is the difference between Modal and Push segue in Storyboards? Interface Builder的“视图-图像视图”关系 - Interface Builder “view - image view” relationship Xcode 11.6 (11E708) 中的 Interface Builder 以 XML 格式显示故事板 - Interface Builder in Xcode 11.6 (11E708) displays storyboards in XML format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM