Iphone 如何正确布局
我只是尝试创建自己的布局。我对我的Iphone 如何正确布局,iphone,ios,objective-c,Iphone,Ios,Objective C,我只是尝试创建自己的布局。我对我的UIViewController使用了UITableView。我有一些来自服务器的JSON响应。这就像是详细的出版物。我还计算了我的UITableViewCell高度,因为我的出版物包含图像和文本的混合。我编写了自己的布局,并在设备旋转时重新计算 for (UIView * sub in contentSubviews) { if([sub isKindOfClass:[PaddingLabel class]]) { Paddin
UIViewController
使用了UITableView
。我有一些来自服务器的JSON响应。这就像是详细的出版物。我还计算了我的UITableViewCell
高度,因为我的出版物包含图像和文本的混合。我编写了自己的布局,并在设备旋转时重新计算
for (UIView * sub in contentSubviews) {
if([sub isKindOfClass:[PaddingLabel class]])
{
PaddingLabel *textPart = (PaddingLabel *)sub;
reusableFrame = textPart.frame;
reusableFrame.origin.y = partHeight;
partHeight += textPart.frame.size.height;
[textPart setFrame:reusableFrame];
} else if([sub isKindOfClass:[UIImageView class]])
{
UIImageView * imagePart = (UIImageView *)sub;
reusableFrame = imagePart.frame;
reusableFrame.origin.y = partHeight;
reusableFrame.origin.x = screenWidth/2 - imageSize.width/2;
reusableFrame.size.width = imageSize.width;
reusableFrame.size.height = imageSize.height;
[imagePart setFrame:reusableFrame];
partHeight += imagePart.frame.size.height;
}
}
但我有一些问题。
当设备更改方向状态时,UIScrollView的偏移量与以前相同。我不知道如何改变它。
轮换前:
轮换后:
我想在rect中保存可见元素。
请推荐。根据您希望在旋转后显示的内容,有两种选择。一种可能的解决方案是在旋转之前获取contentOffset.y/contentSize.height,然后将其乘以新的contentSize.height以派生新的contentOffset.y。或者,如果希望在旋转前后保持特定元素可见,请获取元素_view.frame.origin.y和contentOffset.y之间的差异,然后将新的contentOffset.y设置为元素_view.frame.origin.y+差异