故事板与在代码中做 [英] Storyboards vs. doing it in code

查看:131
本文介绍了故事板与在代码中做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一家公司工作,我们有几个iOS开发人员,我们使用GIT在同一个项目中一起工作。我们从不在我们的开发过程中使用Storyboards或.xib文件,因为几乎不可能正确地合并它们。

I'm working in a company where we have several iOS developers and we use GIT to work in the same projects together. We never use Storyboards or .xib files in our development process as it's nearly impossible to merge them correctly.

随着iOS7的介绍,我想到了故事板和编码所有的UI旧方式之间的根本区别,而不使用Interface Builder。

With the introduction of the iOS7 I thought about the fundamental differences between Storyboards and coding all the UI "the old way", without the use of Interface Builder.

有没有人在这里?最重要的是,你在故事板中可以做什么,你不能在XCode 5的代码中做什么?

Is there anyone here who does just that? And most importantly, is there something you CAN do in Storyboards that you can't do in code in XCode 5?

推荐答案

将会把你的问题分成两部分:NIB和故事板。

I'm going to split your question into two: NIBs, and storyboards.

就NIB而言,源代码控制问题可能很痛苦但却易于管理, ve通常每个视图控制器有一个NIB文件。你可以想象一种情况,你有两个开发人员在NIB应用程序的两个不同部分工作,没有任何合并问题。故事板是不同的,因为你有一个单一的文件,描述了你的应用程序的大多数(如果不是全部)UI。显然,在那里存在潜在的冲突问题。

As far as NIBs are concerned, source control issues can be painful but manageable, mainly because you've typically got one NIB file per view controller. You could imagine a situation where you have two developers working on two different sections of your NIB powered app without any merging issues. Storyboards are different, since you have one single file that describes most - if not all - of the UI of your application. Clearly there is a far greater potential for conflict issues there.

如果使用正确,NIB可以非常有用和节省时间。这里有一个例子:iPhoto App在iPad上有一个非常复杂的UI。绝大多数UI是以程序化的方式布局的。 ,该应用程序还使用NIBs加载图形元素,然后在代码中布局。这是刷面板的工作原理 - 所有的画刷都是在NIB中创建的。这意味着Apple 不需要有几十个相同的image / image视图alloc / init代码。所有的创建都可以在NIB中进行(这在iPhoto UI上的WWDC 2012会话中有一些详细讨论 - 这是非常值得追踪的)。

NIBs can be extremely useful and time saving, if used correctly. Here's an example: the iPhoto App on iPad has a very complex UI. The vast majority of that UI is laid out programatically. However, the app also uses NIBs to load in graphical elements which are then laid out in code. This is how the brush panel works - all the brushes are created in a NIB. This means that Apple don't have to have dozens of identical image/image view alloc/init pieces of code. All the creation can happen in a NIB (this was discussed in some detail in a WWDC 2012 session on the iPhoto UI - it's well worth tracking down).

有时很好,可以节省很多时间,虽然有合并问题,但在许多情况下,它们可以很容易地管理和处理。

So NIBs - sometimes good, can save you a lot of time, and whilst there are merge issues they can in many cases be easily managed and handled.

然后我们来到故事板。故事板是有趣的。一方面,他们非常有用和有用的直接应用程序和开发人员新的平台。我刚刚将一个基于UINavigationController 的应用程序从NIBs转换为故事板,并发现一些显着的时间节省(特别是在表视图,因为故事板你可以利用原型单元格)。

Then we come to storyboards. Storyboards are interesting. On the one hand, they are extremely helpful and useful for straightforward apps and developers new to the platform. I've just converted a UINavigationController based app from NIBs to storyboards and found some significant time savings (particularly around table views, since with storyboards you can take advantage of prototype cells).

但是,如果你正在与一些开发人员合作开发一个大型项目,我不相信storyboards是有益的。正如你所说,正如你所说,合并冲突的大问题,和不同的NIBs是不容易解决它们,因为单个故事板文件控制你的应用程序UI

However, if you're working on a large scale project with several developers I'm not convinced storyboards are that beneficial. There are, as you say, big issues with merge conflicts, and unlike NIBs it's not easy to resolve them since that single storyboard file controls all of your app UI.

这里是我的建议(并随意忽略我!) - 如果你目前正在开发应用程序,并在代码中完成你的布局/ UI 考虑NIB是否可以保存你的时间。他们可能不会 - 他们不是为大家 - 但它是非常值得,至少考虑。你可能会感到惊讶的是,有多少大型应用程序实际使用NIB(iPhoto,正如我所提到的,但是许多由Apple提供的内置应用程序,以及大型团队的许多流行的第三方应用程序)。我可能不会考虑故事板,除非你是一个独立的开发人员在一个应用程序工作相当简单的导航。这不是以任何方式做故事板 - 我喜欢使用它们 - 它只是他们不真正适合协作。

Here's what I'd suggest (and feel free to ignore me!) - if you're currently developing apps and doing your layout/UI entirely in code consider whether NIBs might save you time. They may well not - they're not for everybody - but it's well worth at least considering. You may be surprised at how many large apps actually use NIBs (iPhoto, as I mentioned, but also many built-in apps provided by Apple, as well as many popular third party apps by large teams). I probably wouldn't consider storyboards unless you were a sole developer working on an app with fairly straightforward navigation. That's not to do down storyboards in any way - I love using them - it's just they're not really suitable for collaboration.

有人发表这个评论回复你的问题 - 我想讨论一下:

Somebody posted this comment in reply to your question - I wanted to discuss it:


在故事板中你不能做任何事,也不能在代码中做。

There is nothing you can do in storyboard and can't do in code. Objects, gesture recognizers, segues, even constraints - are all available for you to build programmatically

这是技术上 > true,但是在现实中,故事板/ NIB中的东西比代码更容易。一个很好的例子是汽车布局。尽管你可以完全在代码中管理你的汽车布局约束,但严酷的现实是,ASCII自动布局表示比在IB中获得的可视表示更难工作。这在XCode 5上尤其是 true,在IB中有自动布局的大量改进(我不能详细说明它太多,因为它仍然在NDA下,但苹果公开谈论一些关于更改此处)。

This is technically true, but in reality there are things in storyboards/NIBs that are much easier than code. A good example of this is auto layout. Whilst you can certainly manage your auto layout contraints entirely in code, the harsh reality is that the ASCII auto layout representation is much harder to work with than the visual representation you get in IB. This is especially true on XCode 5, where there are massive improvements to auto layout in IB (I can't detail it too much as it's still under NDA, but Apple publically talk a bit about the changes here).

这篇关于故事板与在代码中做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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