将 CGRectMake (x,x,x,x) 更改为不同的位置,例如 (y,y,y,y)
我使用 CGRectMake(x,x,x,x) 在我的视图中放置了一个按钮,x 当然是位置和大小。当我使用 -(BOOL)shouldAutoRotate... 旋转视图时,我想将按钮的位置从纵向模式的中心更改为横向模式的中心。该按钮在其标签中包含用户设置的信息,因此我不想为横向使用不同的视图。如果他们将某些东西设置为纵向并旋转到水平会怎样?他们会丢失数据。所以我的问题是:如何移动之前设置的内容?请参阅下面的代码,我不想重新分配按钮。谢谢!
// DATE
lblDate = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
lblDate.text = @"Date:";
lblDate.backgroundColor = [UIColor clearColor];
[contentView addSubview:lblDate];
I have placed a button in my view using CGRectMake(x,x,x,x), x being the location and size of course. When I rotate the view using -(BOOL)shouldAutoRotate... I want to change the location of the button from what would be the center in portrait mode to the center in landscape mode. The button contains information in its label that the user sets, so I DON'T want to use a different view for the landscape orientation. What if they set something in portrait and rotate to horizontal? They'll lose their data. So my question is: how do I move something that was previously set? See the code below, I don't want to realloc the button. Thanks!
// DATE
lblDate = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
lblDate.text = @"Date:";
lblDate.backgroundColor = [UIColor clearColor];
[contentView addSubview:lblDate];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需将框架设置为等于新的矩形,例如
Just set the frame equal to a new Rect, e.g.
lblDate.frame = newRect
但是您可能应该为此使用自动调整大小标志。
lblDate.frame = newRect
But you should probably be using autoresizing flags for this.
如 UIView 类参考。
As found in the UIView class reference.