のコピーを作成したいのですが、多くのビューのコピーを頻繁に作成していて、使用が遅いためUIView
、使用したくありません。NSKeyedArchiver
NSKeyedArchiver
copy
またはについて聞いたinitWithZone:
が、グーグルで検索すると、それは良くないことがわかったUIView
。元のビューを指すコピーは必要ありません。元のビューに変更を加えると、コピーされたビューにも変更が加えられるためUIView
です。
以下を使用してビューをコピーできます。
TheView *copyOfView = (TheView *) [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:origionalTheView]];
ビューのコピーに役立つ 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
}