2009-11-05 56 views
0

我需要添加到我的工作的主视图的新子视图。这个子视图应该放在主视图上的所有内容。子视图具有框架= view.frame/2 我试图实现了一些解决方案(下面),但目前还没有结果((递归self.view添加到self.view?

首先

CGRect frame = CGRectMake(100, 140, 250, 250); 
UIView *view = [self.view copy]; 
view.frame = frame; 
[self.view addSubview:view ]; 
[view release]; 

然后

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

不限想法?

+0

被查看应该从不同的观点,因为你混合使用大写查看和小写视图...可能只是格式问题? – 2009-11-05 12:19:23

回答

1

如果我正确理解你的问题,你要self.view的所有子视图移动到一个新视图,然后添加一个新的视图返回到self.view?

也许这样的事情可能做到这一点:

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

希望这有助于

山姆