0

我需要在我的活动主视图中添加一个新的子视图。并且这个子视图应该包含放置在主视图上的所有内容。子视图有一个 frame = view.frame / 2。我尝试实施一些解决方案(如下),但没有结果((

首先关闭

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

有任何想法吗?

4

1 回答 1

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

希望这可以帮助,

山姆

于 2009-11-05T12:36:41.707 回答