开发者

Could one UIView be insert at two different UIView?

开发者 https://www.devze.com 2022-12-25 02:48 出处:网络
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...

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消