
从VIEw HIErarchy调试:
正如您在第2张图片中看到的那样,容器框架已正确定位,而子视图由于某种原因未正确定位.
我真的不知道autolayout会发生什么.
这是处理加载笔尖并将其指定为子视图的代码:
注释掉的代码是我试图使它工作的所有东西,没有成功.我认为autolayout可以独立工作而不需要做任何事情,但默认情况下它加载nib而不调整它.
这意味着前导和顶部锚是正确的,但是笔尖然后使用它的全尺寸……(参见下图)
所以问题是,为了加载笔尖并使其适合容器视图,我需要做些什么?
解决方法 您应该为NibVIEw添加约束,而不是设置NibVIEw的边界和框架.在将NibVIEw添加为内容视图的子视图后,尝试在NibVIEw上调用以下函数(addFullScreenConstraint):
extension UIVIEw { /// Adds constraints to this `UIVIEw` instances `supervIEw` object /// to make sure this always has the same size as the supervIEw. /// Please note that this has no effect if its `supervIEw` is `nil` /// – add this `UIVIEw` instance as a subvIEw before calling this. func addFullScreenConstraints() { guard let supervIEw = self.supervIEw else { return } self.translatesautoresizingMaskIntoConstraints = false supervIEw.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[subvIEw]-0-|",options: .directionLeadingToTrailing,metrics: nil,vIEws: ["subvIEw": self])) supervIEw.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[subvIEw]-0-|",vIEws: ["subvIEw": self])) }} 总结 以上是内存溢出为你收集整理的swift – 使子视图适合容器内部并正确调整大小全部内容,希望文章能够帮你解决swift – 使子视图适合容器内部并正确调整大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)