如何创建uiview的副本(不是指向原始uiview的指针)

Kar*_*gal 5 iphone xcode uiview nscopying ipad

我想创建一个a的副本UIView,我不想使用,NSKeyedArchiver因为我经常创建许多视图的副本,并且使用NSKeyedArchiver速度很慢.

我听说过,copy或者initWithZone:谷歌搜索它发现它不好UIView.我不想要一个指向原始视图的副本,因为对其进行的任何更改也会对复制的内容进行更改UIView.

m4n*_*n1c -4

创建一个 UIView 类别,它可以帮助复制视图。像这样的东西:

- (id) copyView {
     UIView *a = [[UIView alloc]init];
     a.frame = self.frame;
     //set all other properties of the UIView
     return a; //return [a autorelease] if not using ARC
}
Run Code Online (Sandbox Code Playgroud)