使对象居中,使垂直约束始终均匀

centering an object so vertical constraints are always even

我需要将 UIButton('Call') 居中放置在 UIView(拨号盘)和底部布局指南之间。视图始终对齐中心 x 并对齐中心 y。

所以,我希望视图和调用按钮之间以及调用按钮和底部布局指南之间的垂直约束始终相等

UIView('DialPad')约束

UIButton ('Call') 当前包含在底部布局指南中。我希望它在 UIView 和底部布局指南之间均匀分布

故事板预览显示了不同的大小,以及呼叫按钮如何不在 UIView 和底部布局指南之间居中。在 4.7" 布局中非常明显

你想要这个吗?

我对父视图使用比例 width/height。

蓝色视图的宽度限制

高度限制相同。

蓝色视图中按钮的宽度和高度约束

您是否尝试过通过约束在运行时执行此操作? ,方法如下: 你将你的约束设置为当前状态然后你需要将按钮约束(从按钮到底部布局指南的那个)输出到你的 viewController (你这样做就像你输出任何 UIKit 控件一样) 然后在您的 viewWillAppear 或 viewDidAppear 中,您可以编写以下代码:

//here we get the end y point of the dial view . 
CGFloat dialPadYEndPos = self.dialPad.frame.origin.y + self.dialPad.frame.size.height; 
//here we get the space between the dial view and the bottom of the view
CGFloat spaceBetweenViews = self.view.frame.size.height - dialPadYEndPos ; 
//here we get the half of the call button height . 
CGFloat halfBtnHeight = self.Call.frame.size.height/2.0f ;
//then we set the outlet constraint . 
self.bottomConstraint.constant = (spaceBetweenViews/2.0f)-halfBtnHeight ; 
[self.view layoutIfNeeded] ; 

我还没有测试代码,但理论上它应该可以工作。