开发者

Recursive adding self.view to self.view?

开发者 https://www.devze.com 2022-12-11 03:00 出处:网络
I need add to my active main view a new subview. And this subview should be with all content which placed on main view. Subview has a frame = view.frame / 2.

I need add to my active main view a new subview. And this subview should be with all content which placed on main view. Subview has a frame = view.frame / 2. I trying implement some solutions (below), but there are no results ((

First off

 CGRect frame = CGRectMake(100, 1开发者_运维百科40, 250, 250);
 UIView *view = [self.view copy];
 view.frame = frame;
 [self.view addSubview:view ];
 [view release];

Then

 UIView *View = [[[NSBundle mainBundle] loadNibNamed:@"CurrentTemplate" owner:self options:nil] objectAtIndex:0];
 View.frame = CGRectMake(100, 140, 250, 250);
 [self.view addSubview:view ];
 [view release];

Any ideas?


If I understand your question correctly, you want to move all the subviews of self.view into a new view and then add that new view back into self.view?

Perhaps something like this might do it:

// Create a new empty view
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 140, 250, 250)];

// Add each of the children to this new view
NSArray *views = [NSArray arrayWithArray:self.view.subviews];
for (UIView *child in views)
  [view addSubview:child];

// Add the new view as the child of self.view
[self.view addsubview:view];
[view release];

Hope this helps,

Sam

0

精彩评论

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

关注公众号