制作UIView及其所有子视图的深层副本 [英] Make a deep copy of a UIView and all its subviews

查看:123
本文介绍了制作UIView及其所有子视图的深层副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个包含多个子视图的UIView的深层副本。请帮我弄明白怎么做?我已经在google和SO上做了一些搜索,但没有发现任何符合我想要的东西。

I need to make a deep copy of a UIView containing several subviews. Please help me figure out how to do this? I've done some searching on google and SO and not found anything that does what I want.

对于那些想知道原因的人的解释:我有一个无限滚动的UIScrollView,当然,内容重复。每个集合的内容(例如,标记为A-Z的26个UIButtons)包含在一个视图中。这是我需要制作深度副本的视图,以便我可以在scrollview中在屏幕上显示它的多个实例。

Explanation for those who would like to know why: I have an infinitely scrolling UIScrollView where, of course, the contents repeat. Each 'set' of the contents (for example, say 26 UIButtons labeled A-Z) is contained inside one view. This is the view I need to make a deep copy of, so that I can display multiple instances of it onscreen within the scrollview.

我不能简单地重新创建包含按钮的视图的结构,因为按下按钮会调用我的UIScrollView子类无法访问的类的函数。我也不希望重新创建它们,因为当我可以简单地进行深度复制时,通过逻辑重新创建并将所有子视图放在容器视图中似乎是浪费。

I cannot simply recreate the structure of the view containing the buttons, because pressing the buttons calls a function of a class that my UIScrollView subclass does not have access to. Nor would I wish to recreate them, because it seems a waste to go through the logic to recreate and place all subviews in the container view when I could simply make a deep copy instead.

任何人都可以帮助我吗?

Can anyone help me?

推荐答案

(根据我的要求发表评论)

(Posted from my comment on request)

啊哈,我现在看到了。我认为唯一的方法是在运行时创建更多副本并隐藏它们;否则你必须遍历所有子视图,重新创建所有框架,颜色等...但正如你所说,你可能会遇到复制按钮目标等问题 - 但可能有一些有用的东西来帮助实现这一点:

Aha right I see now. I think the only way would be to create more copies at runtime and hide them; else you'd have to iterate through all subviews, re-create all frames, colors etc... but as you say you'd then likely run into issues copying button targets etc - but there might be something useful to help accomplish that here:

如何获得UIButton目标,动作和控制事件?

这篇关于制作UIView及其所有子视图的深层副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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