旋转时更改 UIScrollView 内的子视图框架
我在 UIScrollView 中有几行子视图,我想在旋转到横向模式后重新排列它们。理想情况下,我希望每行有 5 个按钮,总行数由按钮高度和按钮总数(加上一些填充)决定。
我遇到的问题是如何迭代子视图,同时迭代该行上 5 个按钮的 x 位置,然后在达到 5 个按钮限制后更改 y 位置以开始新行。
现在我可以迭代子视图,但我不确定如何自动将框架设置为每行 5 个,然后更改 y 位置以开始新行。任何建议将不胜感激!
for (UIView *subview in someScrollView.subviews)
{
if (subview.tag >= 100) {
[subview setFrame: CGRectMake(x, y, buttonWidth, buttonHeight)];
NSLog(@"%.1f %.1f %d %d on subview %d", x, y, buttonWidth, buttonHeight, subview.tag);
}
}
I have rows of subviews within a UIScrollView that I want to rearrange after rotating to landscape mode. Ideally, I want to have 5 buttons per row with the total number of rows determined by the button height and how many buttons there are total (plus some padding).
The problem I am having is how to iterate through subviews while also iterating through x-position for 5 buttons on the row and then changing y-position after I hit the 5 button limit to start a new row.
Right now I can iterate through subviews, but I'm not sure how to automate setting the frame for 5 per row and then changing the y-position to start a new row. Any suggestions are greatly appreciated!
for (UIView *subview in someScrollView.subviews)
{
if (subview.tag >= 100) {
[subview setFrame: CGRectMake(x, y, buttonWidth, buttonHeight)];
NSLog(@"%.1f %.1f %d %d on subview %d", x, y, buttonWidth, buttonHeight, subview.tag);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白...还是谢谢大家。
对于纵向模式:
对于横向模式:
I dun' figured it out... thanks all the same.
For portrait mode:
For landscape mode: