2013-07-29 3 views
0

나는 내 자신의 레이아웃을 만들려고 노력합니다. 내 UIViewControllerUITableView을 사용했습니다. 서버에서 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 오프셋이 동일 할 때. 나는 그것을 어떻게 바꿀 지 모른다. 회전하기 전에 :

enter image description here

회전 후 :

enter image description here

나는 RECT에 보이는 요소를 저장할. 제안 pls.

답변

0

회전 후 표시 할 항목에 따라 몇 가지 선택 사항이 있습니다. 한 가지 가능한 해결책은 회전하기 전에 contentOffset.y/contentSize.height를 가져온 다음 새로운 contentSize.height에 여러 contentOffset.y를 곱하여 새 contentOffset.y를 유도하는 것입니다. 또는 순환 전후에 특정 요소를 계속 표시하려면 element_view.frame.origin.y와 contentOffset.y의 차이점을 가져온 다음 new contentOffset.y를 element_view.frame.origin.y + difference로 설정하십시오.

관련 문제