刷新 viewController 时,我的按钮位置不正确

Posted

技术标签:

【中文标题】刷新 viewController 时,我的按钮位置不正确【英文标题】:My button not appears to correct position when viewController is refreshed 【发布时间】:2015-05-20 07:35:17 【问题描述】:

我正在使用这个框架大小以编程方式创建一个简单的 UIButton

UIButton *pickmeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 100, self.view.bounds.size.width, 60)];

它显示在我想要的完美位置

但是在某些操作上我想重新加载整个视图控制器,当我这样做时,它会在错误的坐标处显示按钮

首先,我找不到它的原因。其次,根据我定义的坐标,我认为第二个图像正在渲染正确的坐标,因为 Y 坐标上的位置是(self.view.bounds.size.height - 100)并且高度是 60。但是当我制作它 -60 它开始在底线下方显示按钮,并且很少有按钮显示在上方。

请分享您对此的看法和解决方案。

【问题讨论】:

【参考方案1】:

为按钮设置 AutoresizingMask

 UIButton *pickmeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 60, self.view.bounds.size.width, 60)];
 [pickmeButton setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];

【讨论】:

【参考方案2】:

请尝试一下。

UIButton *pickmeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 60, [UIScreen mainScreen].bounds.size.width, 60)];

【讨论】:

以上是关于刷新 viewController 时,我的按钮位置不正确的主要内容,如果未能解决你的问题,请参考以下文章