我遇到了自定义 UIView 的自动布局问题,该问题在 iphone XR 中正确呈现 如
并在 Storyboard中仅使用 View Controller (UI)进行设置,并且没有指定的 UIViewController 类,为了简化起见,我只想调试 View ,因此我不将任何 View Controller 类与其关联。
p.s安全区域已被使用
和自定义类 UI(FilterView) 设置: 和自定义类 UI(FilterView) 代码:
override init(frame: CGRect){
super.init(frame: frame)
setUpView()
}
//for IB
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setUpView()
}
private func setUpView(){
Bundle.main.loadNibNamed(Constants.NIB_FILTER_VIEW_NAME, owner: self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
contentView.autoresizingMask = []
contentView.translatesAutoresizingMaskIntoConstraints = true
}
有人知道这里发生了什么吗?
最佳答案
您不应该以这种方式创建 X 按钮和“排序依据”标签。您正在做的是复制 UINavigationController 的功能。如果您想要该布局,请将 View Controller 放入 UINavigationController 中,这将使添加 X 和“排序依据”标签变得更加容易。
此外,通过执行此操作,您可以添加一个 rightBarItem
作为“重置”按钮。再说一次,你不必把它摆出来。 UINavigationController 会为您完成所有这些工作。
关于iOS 自定义 UIView 在 iphone xr 和 iphone 7 中具有不同的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56551206/