从顶部降低UIView的高度

时间:2018-05-31 12:10:15

标签: ios swift uiview

我只是想设置frame的{​​{1}},但是当您尝试缩小UIView视图时,它会从视图底部缩小,而不是最佳。如何从顶部而不是从底部更改视图的高度?

height

5 个答案:

答案 0 :(得分:2)

您可以更新frame.origin.y和高度。

如果reduceHeightSize为正;

customView = CGRect(x: self.view.frame.origin.x, y: self.view.frame.origin.y + reduceHeightSize , width: self.view.frame.width , height: self.view.frame.height - reduceHeightSize)

如果你将它存储为负的reduceHeightSize;

customView = CGRect(x: self.view.frame.origin.x, y: self.view.frame.origin.y - reduceHeightSize , width: self.view.frame.width , height: self.view.frame.height + reduceHeightSize)

最好只保持大小不是方向。

答案 1 :(得分:0)

你需要这样做......

customView = CGRect(x: 0, y:reduceHeightSize , width: self.view.frame.width , height: self.view.frame.height - reduceHeightSize)

答案 2 :(得分:0)

customView = CGRect(x: 0, y:0 , width: self.view.frame.width , height: self.view.frame.height - reduceHeightSize)

您的代码问题是您在Height中更改了CGRect。并且您想要更改view的顶部位置,因此您需要更改视图的y的位置,以便最终您的代码将

customView = CGRect(x: 0, y: reduceHeightSize , width: self.view.frame.width , height: self.view.frame.height - reduceHeightSize)

答案 3 :(得分:0)

如果我正确理解你的问题,可能是因为你的观点没有受到限制/锚定在底部,因此默认会在顶部减少。尝试添加底部约束。

答案 4 :(得分:0)

我只是想出了我需要的东西:

  customView.frame = CGRect(x: 0, y: self.view.frame.origin.y - reduceHeightSize , width: self.view.frame.width , height: self.view.frame.height + reduceHeightSize)
相关问题