There are three UIView *view1,view2 , view3; Now, view1 have to be shown at both of view2 and view3 at the same time. But as usually, one view could be insert at only one view... Is there an开发者_如何学编程y method to insert one view at two different view ?
No. A UIView instance can only be a subview of exactly 1 other UIView instance.
You need to create 2 UIView instances. To avoid code duplication, you could subclass UIView:
@interface MyView1 : UIView { ... }
-(id)initView1WithFrame:(CGRect)frame;
@end
...
and create 2 instances of MyView1, and add them as subviews of view2 and view3 respectively:
MyView1* view1a = [[MyView1 alloc] initWithFrame:...];
[view2 addSubview:view1a];
[view1a release];
MyView1* view1b = [[MyView1 alloc] initWithFrame:...];
[view3 addSubview:view1a];
[view1b release];
精彩评论