如何改变物体的中心?
How to change center of object?
这是我用来将按钮居中显示在屏幕底部的代码:
CGFloat centro = self.view.center.x;
CGFloat bottom = CGRectGetMaxY(self.view.frame);
_sendButton.center = CGPointMake(centro, bottom);
但是,按钮的实际中心设置在屏幕底部,覆盖了一半的按钮。我如何设置它以便将按钮上的最低点设置为:
CGPointMake(centro,bottom)
相反?
您需要减去按钮高度的一半:
CGFloat centro = self.view.center.x;
CGFloat bottom = CGRectGetMaxY(self.view.frame) - _sendButton.frame.size.height / 2.0;
_sendButton.center = CGPointMake(centro, bottom);
这是我用来将按钮居中显示在屏幕底部的代码:
CGFloat centro = self.view.center.x;
CGFloat bottom = CGRectGetMaxY(self.view.frame);
_sendButton.center = CGPointMake(centro, bottom);
但是,按钮的实际中心设置在屏幕底部,覆盖了一半的按钮。我如何设置它以便将按钮上的最低点设置为:
CGPointMake(centro,bottom)
相反?
您需要减去按钮高度的一半:
CGFloat centro = self.view.center.x;
CGFloat bottom = CGRectGetMaxY(self.view.frame) - _sendButton.frame.size.height / 2.0;
_sendButton.center = CGPointMake(centro, bottom);