2010-11-25 9 views
4

스크롤 나는 사랑의 example for Multi-row selection과 같이, 각 행의 왼쪽에 체크 박스를 표시 layoutSubviews에 애니메이션을 시작하는 사용자 지정있는 UITableViewCell 만드는 작업이 포함되는 코코아를 구현했습니다 :있는 UITableViewCell 애니메이션

- (void)layoutSubviews 
{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 

    [super layoutSubviews]; 

    if (((UITableView *)self.superview).isEditing) 
    { 
     CGRect contentFrame = self.contentView.frame; 
     contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET; 
     self.contentView.frame = contentFrame; 
    } 
    else 
    { 
     CGRect contentFrame = self.contentView.frame; 
     contentFrame.origin.x = 0; 
     self.contentView.frame = contentFrame; 
    } 

    [UIView commitAnimations]; 
} 

이 잘 작동을 모든 의향과 목적을 위해 내 UITableView는 필요한대로 동작합니다. 그러나 나는 작은 미적 문제에 직면하고있다. 이전에 표시되지 않은 UITableView 행을 스크롤하면 슬라이딩 애니메이션이 시작될 것이다. 즉, 애니메이션이 특정 행에 대해 시야에 비틀 거리는 것을 의미한다.

setAnimationBeginsFromCurrentState가 YES로 설정되어 있고 UITableView에서 더 아래쪽의 행이 아직 프레임 위치가 업데이트되지 않은 경우에 이해할 수 있습니다. 이 문제를 해결하기 위해 willDisplayCell을 사용하여 UITableView가 편집 모드에있는 동안 보이는 셀의 애니메이션을 재정의하려고했습니다. 기본적으로 애니메이션을 무시하고 셀이 이미 같은 장소로 애니메이션 한 것처럼 보이게하기 위해, 즉시 행 프레임을 업데이트 :

/* 
Since we animate the editing transitions, we need to ensure that all animations are cancelled 
when a cell is scheduled to appear, so that things happen instantly. 
*/ 
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    [cell.contentView.layer removeAllAnimations]; 

    if(tableView.isEditing) { 
     CGRect contentFrame = cell.contentView.frame; 
     contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET; 
     cell.contentView.frame = contentFrame; 
    } else { 
     CGRect contentFrame = cell.contentView.frame; 
     contentFrame.origin.x = 0; 
     cell.contentView.frame = contentFrame; 
    } 
} 

불행하게도이 어떤 영향을 미칠 것 같지 않습니다. 아무도 내가이 문제를 해결할 수있는 방법에 대한 아이디어가 있습니까?

답변

1

이 질문에 대한 대답이 여전히 필요하지만 정확히 동일한 문제에 부딪혔을 때 확실하지 않으므로 솔루션을 공유 할 것이라고 생각했습니다. 내가 언급 한 코코아 러브 (Cocoa with Love) 블로그 게시물에서 설명한 것과 같은 방법으로 멀티 셀렉션을 구현했습니다.

cellAtIndexPath DataSource 메서드에서 새 셀을 만들 때 (셀이 이미 재사용 가능한 셀의 큐에없는 경우) tableView가 편집 모드에 있는지 확인하고 셀에 속성을 설정하면 EnableAnimation 속성을 가진 내 자신의 사용자 지정 셀을 만들었습니다. false로 설정하면 SetEditing 콜백을 가져 오면 셀을 애니메이션화하지 않고 대신 프레임을 설정합니다. Cell 클래스의 생성자에서 EnableAnimation을 true로 설정하면 SetEditing 콜백이 호출 될 때 전달되는 애니메이션 인수로 EnableAnimation을 설정합니다. 도움이 되었기를 바랍니다.