[英]self.view insertSubView … not supposed to be self.view, but what?
[英]Recursive adding self.view to self.view?
我需要在我的活动主视图中添加一个新的子视图。 并且此子视图应具有放置在主视图上的所有内容。 Subview有一个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];
有任何想法吗?
如果我正确理解了您的问题,您想将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];
希望这可以帮助,
山姆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.