在故事板中的视图控制器之外的UIView [英] UIView outside of a View Controller in a Storyboard

查看:99
本文介绍了在故事板中的视图控制器之外的UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我无法在官方文档,Stackoverflow或Google上找到答案。

I'm stuck with a question I can't find an answer to in the official documentation, on Stackoverflow or on Google.

我是一位经验丰富的iOS开发人员,但却是Storyboards的新手。我想在当前的viewcontroller上实例化一个视图,在NIB中,我会在viewController之外绘制并附加一个插座以在代码中引用它并调用类似addSubview:或类似的东西。绘制叠加层是有用的,或者在我目前的情况下,绘制一个用于MapView委托的标注视图。但我无法弄清楚如何在故事板中做到这一点。

I'm an experienced iOS developer but new to Storyboards. I'd like to instantiate a view on the current viewcontroller, a view that, in a NIB, I would draw outside the viewController and attach an outlet to to refer to it in code and call something like addSubview: or so. It's useful to draw an overlay or, in my current case, a callout view for use in a MapView delegate. But I can't figure out how I can do this in a Storyboard.

我似乎看不到视图控制器之外的视图,视图控制器内的视图必须是控制器视图的子视图,或者在视图中不可见完全是Interface Builder(在传统的NIB中拖动外部视图时可以,但如果你需要调整它的最不详细的话,这是一个很大的问题)。

I can't seem to have a view outside of a viewcontroller, and views inside the viewcontroller either have to be subviews of the controller's view or don't be visible in Interface Builder at all (which is okay when you drag a view composed outside, in a traditional NIB, but quite a problem if you need to tweak even the least detail of it).

有关做什么或在哪里看的任何提示?谢谢。

Any hint on what to do or where to look? Thanks.

推荐答案

似乎无法做到这一点。请参阅 Jason的评论这个问题解决同样的问题,尽管在不同的背景。

It appears there is no way to do it. See Jason's comment and this question addressing the same problem, though in a different context.

然而,我在考虑问题的影响时早些时候意识到 - 我开始在我之前的评论,然后才决定是否值得一个完整的答案 - 将自定义设计分开是有意义的从应用程序流程的设计来看。因此,在Storyboard中设计自定义视图是不可能的,这很可能是......设计。

However, I realised earlier when thinking about the implications of my problem — as I began to explain in my previous comment before deciding it would be worth a full answer — it makes sense to separate the design of a custom view from the design of an application flow. So the fact that it's not possible to design custom views in Storyboards may very well be... by design.

自定义视图(可重用组件)与视图控制器(代表应用程序故事板中的场景)非常不同。它与电影中的角色和场景相同。即使您恰好在一个场景中使用该角色,也不希望在场景中设计角色。如果你只在一个场景中使用它,这是偶然的,但不是必需的。所以它必须是分开的。

A custom view (which is a reusable component) is very different from a view controller (which represents a scene in your application storyboard). It's the same as a character and a scene, in a movie. You don't want to design your character in your scene, even if you happen to use that character in only one scene. It's fortuitous if you use it in only one scene, but not essential. So it has to be separate.

您希望使用Interface Builder设计自定义视图的事实只是一个实现细节,应该封装在你的类中。应用程序故事板无需了解甚至更少管理您如何处理可重用视图的特定实现。

The fact that you want to use Interface Builder to design your custom view is only an implementation detail that should be encapsulated in your class. The application storyboard has no need of knowing, even less managing, how you deal with the particular implementation of your reusable view.

嗯,我希望我有更多这个品牌的讯问:)

Hmm, I wish I had more of this brand of interrogation :)

这篇关于在故事板中的视图控制器之外的UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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