【发布时间】:2021-02-11 08:19:29
【问题描述】:
如何使用约束将 UIView 添加到 UIView 的底部
bottomView = UIView(frame:CGRect(x:0, y:leftMenuView.frame.height - 64, width: leftMenuView.frame.size.width, height:64))
bottomView.translatesAutoresizingMaskIntoConstraints = false
leftMenuView.addSubview(bottomView)
func setUpBottonViewConstrain(){
NSLayoutConstraint.activate([
bottomView.leadingAnchor.constraint(equalTo: self.leftMenuView.safeAreaLayoutGuide.leadingAnchor),
bottomView.trailingAnchor.constraint(equalTo: self.leftMenuView.safeAreaLayoutGuide.trailingAnchor),
bottomView.topAnchor.constraint(equalTo: self.leftMenuView.safeAreaLayoutGuide.bottomAnchor,constant:-64),
bottomView.bottomAnchor.constraint(equalTo: self.leftMenuView.safeAreaLayoutGuide.bottomAnchor),
])
}
在 iPhone 5s 中工作正常,但在 iPhone12 中没有固定到底部的缺口
【问题讨论】:
-
使用
bottomView.bottomAnchor.constraint(equalTo: self.leftMenuView.bottomAnchor)removesafeAreaLayoutGuide假设您的 leftView 固定在屏幕底部,它将固定到底部,否则也对leftMenuView应用类似的约束
标签: swift uiview autolayout constraints