2014-02-13 4 views
3

방향에 따라 크기가 조정되는 tableview 헤더 (섹션 헤더 아님)가있는 tableview가 있습니다. 내 구현에서는 viewWillLayoutSubviews에서 두 뷰의 프레임을 설정합니다.회전 및 크기 조정 후 UITableView 및 UITableViewHeader가 충돌합니다.

내 문제는 바로 지금 둘 다 회전 후 개별적으로 크기가 조정되는 동안 tableView의 원점이 헤더의 높이 변경을 고려하여 변경되지 않는다는 것입니다. 이것은 그들 사이에 나타나는 공간이나 세포의 일부를 덮고있는 머리말을 이끌고있다.

제 목표는 세로로 길게 만드는 것입니다. 테이블 뷰는 화면 너비가 길고 헤더가 길어야합니다. 가로로 회전하면 너비는 화면 너비의 1/3로 줄어들고 오른쪽 끝은 더 짧은 머리글로 줄어 듭니다. 또한 이러한 모든 변경 사항이 부드럽고 논리적 이도록 회전 애니메이션이 필요합니다.

iOS 회전 및 애니메이션 관행에 상당히 녹초가 없으므로 누구에게나 더 나은 제안이 있다면 분명히 감사하겠습니다.

답변

1

테이블 뷰는 tableHeader를 재할 당할 때까지 새 머리글 높이를 고려하지 않습니다.

비슷한 질문 :

때 회전거나 한 다음 할 수있는 마무리 :

- (void)didRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    self.tableView.tableHeaderView = self.tableView.tableHeaderView; 
} 

사실은, 여기 또한 헤더의 높이를 계산할 수있는 장소 : 아이폰 OS에

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    CGRect frame = self.tableView.tableHeaderView.frame; 
    frame.size.height = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 50 : 150; 
    self.tableView.tableHeaderView.frame = frame; 

    self.tableView.tableHeaderView = self.tableView.tableHeaderView; 
} 
+1

안녕하세요, 헤더를 재 할당하는 것은 내가 빠뜨린 것입니다. 헤더 프레임을 설정 한 후 selfTableView.tableHeaderView를 사용하여 setTableHeaderView를 호출했습니다. 이제 모든 것이 멋지게 보입니다. 고마워. –

+1

첫 번째 코드 예제의 메소드 서명은'-didRotateToInterfaceOrientation : duration :'대신'-didRotateFromInterfaceOrientation :'이어야합니다. – Frederik

0

를 8.0 이상 대신 호출 할 수 있습니다 : 당신이 메소드를 오버라이드 (override)하는 경우

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator; 

, 당신이 최고 전화 확인 어떤 시점에서.

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 

    coordinator.animate(alongsideTransition: { (UIViewControllerTransitionCoordinatorContext) in 



     self.tableView.tableHeaderView? = YourTableHeaderView() 

    }, completion: { (UIViewControllerTransitionCoordinatorContext) in 



    }) 

    super.viewWillTransition(to: size, with: coordinator) 
} 
관련 문제