0

当我尝试在我的 iPhone 应用程序中更改 UIButton 的位置时,它不起作用。

我正在使用这样的代码:uxButton.center = CGPointMake(0,0);但是按钮停留在我之前在情节提要上放置的位置。我也试过改变这个按钮的框架。我在这里可能做错了什么?

4

1 回答 1

0

这将在您的屏幕中央纵向创建一个按钮:

UIButton* xButton = [[UIButton alloc]initWithFrame:CGRectMake((320-yourwidth)/2, y, yourWidth, yourHeight)];

如果你想让故事板中的按钮设置它的框架:

xButton.frame = CGRectMake((320-yourwidth)/2, y, yourWidth, yourHeight);

编辑一个例子:

UIButton* xButton = [[UIButton alloc]initWithFrame:CGRectMake((320-50)/2, 300, 50, 30)];

当您的键盘将显示:

[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
    xButton.center = CGPointMake(xButton.frame.origin.x, 30);
} completion:nil];

此代码将向上移动您的按钮

于 2013-09-16T21:18:11.327 回答