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

查看:27
本文介绍了使用 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. 在团队内部工作变得更加困难,因为 Storyboard 中的冲突可能难以解决(也欢迎任何与此相关的提示)
  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 一个地方吗?这篇文章对许多问题进行了很好的概述,并建议对于只有一个屏幕的场景,这种情况下应该使用 xibs.Apple 支持从情节提要中实例化未连接的场景,这再次让我感到不寻常,这表明 xibs 将来不会有一席之地,但我可能是错的.

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 可以保存 UIView 的集合,因此它们非常适合直观地创建自定义控件.在 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 中发布类似的功能.但是,既然你问了,我决定现在就发布它.您可以在我的 博客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天全站免登陆