Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何正确布局_Iphone_Ios_Objective C - Fatal编程技术网

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+差异