拜托,我需要一些必须包含动态内容的 UILabel 的帮助。它们包含在 UIScrollView 中。
我无法让它们根据屏幕方向正确调整大小。我也想在他们之间保持准确的距离。现在,我遇到了其中 2 个问题(还有很多)。
我正在使用以下代码来调整它们的大小,但它没有得到预期的结果:
- (void) updateLabelsPositionForPortrait
{
summary_PersonalMonth.numberOfLines = 0;
summary_PersonalDay.numberOfLines = 0;
summary_PersonalMonth.frame = CGRectMake(summary_PersonalMonth.frame.origin.x,
summary_PersonalMonth.frame.origin.y,
summary_PersonalMonth.frame.size.width + 15,
summary_PersonalMonth.frame.size.height);
[summary_PersonalMonth sizeToFit];
summary_PersonalDay.frame = CGRectMake(summary_PersonalDay.frame.origin.x,
summary_PersonalDay.frame.origin.y + summary_PersonalMonth.bounds.origin.y + 10,
summary_PersonalDay.frame.size.width + 15,
summary_PersonalDay.frame.size.height);
[summary_PersonalDay sizeToFit];
[self updateScrollViewContentSize];
}
- (void) updateLabelsPositionForLandscape
{
summary_PersonalMonth.numberOfLines = 1;
summary_PersonalDay.numberOfLines = 1;
summary_PersonalMonth.frame = CGRectMake(summary_PersonalMonth.frame.origin.x,
summary_PersonalMonth.frame.origin.y,
summary_PersonalMonth.frame.size.width,
summary_PersonalMonth.frame.size.height);
[summary_PersonalMonth sizeToFit];
summary_PersonalDay.frame = CGRectMake(summary_PersonalDay.frame.origin.x,
summary_PersonalDay.frame.origin.y - summary_PersonalMonth.bounds.origin.y - 10,
summary_PersonalDay.frame.size.width,
summary_PersonalDay.frame.size.height);
[summary_PersonalDay sizeToFit];
}
我在 shouldAutorotateToInterfaceOrientation: 中以相应的方向调用每个方法。
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
[self updateLabelsPositionForPortrait];
}
else
{
[self updateLabelsPositionForLandscape];
}
结果如下:
- 视图加载的初始结果
- 横向旋转后的结果
- 转回纵向后的结果
拜托,我需要建议!
谢谢 !