可以复制UIView吗? [英] Can UIView be copied?

查看:306
本文介绍了可以复制UIView吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需使用此方式

UIView* view2 = [view1 copy]; //view1 existed

这将导致模拟器无法启动此应用程序。

This will cause simulator can not launch this app.

尝试保留,

UIView* view2 = [view1 retain]; //view1 existed
//modify view2 frame etc

对view2的任何修改都将应用于view1,我理解view2与view1共享同一内存。

Any modifications to view2 will apply to view1, I understand that view2 share same memory with view1.

为什么不能复制 UIView ?原因是什么?

Why can't UIView be copied? What is the reason?

推荐答案

您的应用程式可能会发生崩溃,例如:

Your app probably crashes with something like:

 [UIView copyWithZone:]: unrecognized selector sent to instance 0x1c6280

原因是UIView没有实现复制协议,因此在UIView中没有 copyWithZone 选择器。

The reason is that UIView does not implement the copying protocol, and therefore there is no copyWithZone selector in UIView.

这篇关于可以复制UIView吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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