子视图如何在父视图中指定位置显示

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/09 19:09:21
子视图如何在父视图中指定位置显示

子视图如何在父视图中指定位置显示
子视图如何在父视图中指定位置显示

子视图如何在父视图中指定位置显示
------解决方案--------------------------------------------------------
除去设置subview 的frame 位置为父视图顶部外,在添加subview 时需要send to front.
[self.view insertSubView:subview atIndex:0];
------解决方案--------------------------------------------------------
CGRect parentBounds = parentView.bounds;
CGFloat x = parentBounds.origin.x;
CGFloat y = parentBounds.origin.y + parentBounds.size.height / 2;
CGFloat width = parentBounds.size.width;
CGFloat height = parentBounds.size.height / 2;
subView.frame = CGRectMake(x,y,width,height);
// 上面的parentView 就是父视图,记得是取bounds,而不是frame,因为子视图是在父视
图的相对坐标系中,而不是父视图相对祖父视图的坐标系.这两个坐标系一般情况是相同的,
但是如果进行了缩放就不一样了.
// subView 就是你要显示的子视图
------解决方案--------------------------------------------------------
简单来说你需要根据bounds 来做.
复杂来说,你可以看resize in uikit一句话说不清楚