【发布时间】:2020-04-04 14:39:54
【问题描述】:
我的UIView 的height 怎样才能在实际呈现之前?
这是我尝试过的:
print(wishWishView.frame.size.height)
self.view.addSubview(self.wishWishView)
wishWishView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
wishWishView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
wishWishConstraint = wishWishView.topAnchor.constraint(equalTo: self.view.bottomAnchor)
wishWishConstraint.isActive = true
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
self.transparentView.alpha = 0.7
self.wishWishConstraint = self.wishWishView.topAnchor.constraint(equalTo: self.view.bottomAnchor, constant: - self.keyboardHeight)
self.view.layoutIfNeeded()
}, completion: nil)
问题是在实际呈现视图之前,wishWishView.frame.size.height 是 0。
我真正想要实现的是将视图隐藏在底部。我知道我可以只使用constant: 1000,但这是相当蛮力的,而且不是很干净。
编辑:
流程:
1.用户点击按钮
2. 视图从底部到右侧出现在 kayboard 上方
3.用户关闭视图
4.视图移到视图底部
我拥有所有 functions 和 variables(func viewAppears、keyboardHeight、...),但我正在为 constraints 苦苦挣扎。
【问题讨论】:
-
你想用第一个约束做什么?您将 wishWishView 的高度设置为等于自身。
-
只是设置
height -
你想让
wishWishView和self.view一样高吗?您需要设置它相对于另一个视图的高度或将其设置为常数。将其等同于自身没有任何作用。 -
哦刚刚也意识到了.. 删除它,谢谢。您知道如何解决主要问题吗?
-
@Chris 那会很有帮助。我为我们创建了一个聊天室here
标签: ios swift uiview constraints