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

查看:23
本文介绍了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,我知道view2view1 共享相同的内存.

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天全站免登陆