开发者

Could one UIView be insert at two different UIView?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜