使用UIStoryboards时的最佳做法是什么? [英] What is the best practice when using UIStoryboards?

查看:109
本文介绍了使用UIStoryboards时的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我已经使用了故事板一段时间了,但我发现它们非常有用,但是它们确实有一些限制,或者至少是不自然的做事方式。虽然看起来应该为您的应用程序使用单个故事板,但是当您达到中等大小的应用程序时,这会出现一些问题。

Having used storyboards for a while now I have found them extremely useful however, they do have some limitations or at least unnatural ways of doing things. While it seems like a single storyboard should be used for your app, when you get to even a moderately sized application this presents several problems.


  1. 团队内部的工作变得更加困难,因为故事板中的冲突可能会有问题需要解决(任何提示都会受到欢迎)

  2. 故事板本身可能变得非常混乱和无法管理。

所以我的问题是什么是最好的使用的做法?

So my question is what are the best practices of use?

我考虑过使用混合方法将逻辑任务拆分成单独的故事板,但这导致UX流程在代码和故事板之间分开。对我而言,这是创建可重复使用的操作(如登录操作等)的最佳方式。

I have considered using a hybrid approach having logical tasks being split into separate storyboards, however this results in the UX flow being split between the code and the storyboard. To me this feels like the best way to create reusable actions such as login actions etc.

我还应该考虑一下Xibs的位置吗? 这篇文章对许多问题进行了很好的概述,并提出了对于只有一个屏幕的场景,在这种情况下应该使用xib。再次,这对我来说不太常见,苹果支持从故事板中实例化未连接的场景,这表明xib将来不会占有一席之地,但我可能错了。

Also should I still consider a place for Xibs? This article has quite a good overview of many of the issues and it proposes that for scenes that only have one screen, xibs should be used in this case. Again this feels unusual to me with Apples support for instantiating unconnected scenes from a storyboard it would suggest that xibs won't have a place in the future but I could be wrong.

推荐答案

你是对的,打破故事板是最好的方法。分解不仅仅是使UI的一部分更具可重用性。它还使团队中的故事板更易于管理。

You are correct, breaking up the storyboards is the best way to go. Decomposition does more than just make parts of the UI more reusable. It also makes using storyboards in a team more manageable.

最近,我的很多故事板都包含了四个或更少的场景。对于一个人来说,单独构建和维护一个或多个这样的UI模块是很容易的。这种做法减少或消除了合并冲突。

Lately, many of my storyboards have contained four or less scenes. It is easy enough for one person to solely build and maintain one or more of such UI modules. This practice reduces or eliminates merge conflicts.

如果我确实需要在其他人拥有的故事板中更改某些内容,我会先询问所有者他或她是否有任何本地更改。如果是这样,我有时会让所有者为我添加更改。分解仍然需要一些协调,但它远远低于完整的应用程序故事板。自从我开始这种做法以来,我没有任何合并困难。

In the case I do need something changed in a storyboard owned by someone else, I ask the owner first if he or she has any local changes. If so, I sometimes have the owner add the changes for me. Decomposition still requires some coordination, but it is substantially less than a full-app storyboard. Ever since I started this practice, I haven't had any merge difficulties.

至于XIB,我认为我在文章中没有写过足够多的内容。它们仍然非常有用。它们可以用于单视图控制器。然而,这不是他们真正发光的地方。 XIB具有故事板可能永远不会具有的一个优点。 XIB的最基本单元是UIView,而故事板的基本单元是UIViewController。由于XIB可以容纳UIViews的集合,因此它们非常适合直观地创建自定义控件。在XIB中,我可以直观地构建旋转拨盘或GPS小部件。然后我可以将这些控件和小部件放到故事板或其他XIB中。这样的XIB在iPad应用程序中更常见,因为它们具有能够容纳许多控件和小部件的更大屏幕。在故事板中的UIViewController中构建UISwitch是不自然的。

As for XIBs, I don't think I wrote enough about them in my article. They are still very useful. They can be nice for single view controllers. However, this is not where they truly shine. XIBs have one advantage that storyboards may never have. The most basic unit of a XIB is a UIView, whereas the basic unit of a storyboard is a UIViewController. Since XIBs can hold collections of UIViews, they are great for visually creating custom controls. In a XIB, I can visually build a rotary dial or a GPS widget. Then I can drop these controls and widgets into storyboards or other XIBs. Such XIBs are seen more often in iPad apps since they have larger screens capable of holding many controls and widgets. It would be unnatural to build a UISwitch within in a UIViewController in a storyboard.

现在是最好的消息。可以在Interface Builder中连接故事板,而无需编写任何代码。我计划在WWDC之后发布这种技术,因为Apple可能会在iOS 6中发布类似的功能。但是,既然你问过,我现在决定发布它。我可以在博客上找到更多详细信息,而不是重复我对RBStoryboardLink如何工作的解释。 GitHub 。这将使您的UIStoryboard体验更加愉快。

Now for the best news. It is possible to connect storyboards within Interface Builder and without writing any code. I was planning on releasing this technique after WWDC, since Apple may release similar functionality in iOS 6. However, since you asked, I decided to release it now. Rather than duplicate my explanations on how RBStoryboardLink works, you can find more details on my blog and on GitHub. This will make your UIStoryboard experiences much more enjoyable.

这篇关于使用UIStoryboards时的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆