大佬教程收集整理的这篇文章主要介绍了swift – 使子视图适合容器内部并正确调整大小,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
从View Hierarchy调试:
正如您在第2张图片中看到的那样,容器框架已正确定位,而子视图由于某种原因未正确定位.
我真的不知道autolayout会发生什么.
这是处理加载笔尖并将其指定为子视图的代码:
注释掉的代码是我试图使它工作的所有东西,没有成功.我认为autolayout可以独立工作而不需要做任何事情,但默认情况下它加载nib而不调整它.
这意味着前导和顶部锚是正确的,但是笔尖然后使用它的全尺寸……(参见下图)
所以问题是,为了加载笔尖并使其适合容器视图,我需要做些什么?
在将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 – 使子视图适合容器内部并正确调整大小所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。