【发布时间】:2014-04-24 11:10:09
【问题描述】:
我需要提取所有嵌套的子视图(从多个视图中)并添加它们,并将它们正确定位到一个 UIView 1 级深度。
NSArray*contentViews; // views with complicated nesting of subViews
UIView *flatView; // All the subviews but as simple subviews of the parent.
[self deepCopyAllSubviews:[contentViews[i++] subviews] to newView:flatView];
我的问题是如何找到与 flatView 相关的正确原点?
-(void) deepCopyAllSubviews:(NSArray*)subviews newView:flatView {
[subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CGRect frame = [(UIView*)obj frame];
frame.origin.x = ??
[(UIView *)obj setFrame:frame];
[flatView addSubview:obj];
NSArray *subs = [(UIView*)obj subviews];
if ([subs count]>0) {
[self deepCopyAllSubviews:subs newView:flatView];
}
}];
}
【问题讨论】:
-
我没有得到你的问题,但框架会给你 x 和 y 相对于它的父级的位置,其中 bound 将以绝对方式给出 x 和 y 位置。
-
将子视图框架的原点添加到其父框架的原点以及其父框架的原点等等。
标签: ios objective-c xcode uiview