2012-12-10 8 views
1

이것이 가능하다는 것이 확실하지 않지만 여기에 제 시나리오가 있습니다.이 tableView는 3 섹션으로 구성되어 있습니다. accessoriesImage의 세 번째 섹션에서 흰색 별을 터치하면 해당 행이 accessories.sku와 마찬가지로 즐겨 찾기 섹션에 삽입됩니다. 그건 잘 작동합니다.스크롤에서 tableView를 중지하십시오.

이제 즐겨 찾기에 행을 추가하면 즐겨 찾기 섹션이 커져서 세 번째 섹션이 화면 아래로 밀려납니다. 섹션 2에 행을 추가 할 때이 작업이 필요하다는 것은 분명합니다. 그러나 마지막 섹션에는 400 개가 넘는 행이 있으며 화면의 상단 두 섹션을 매우 빠르게 스크롤 할 수 있습니다. 여기서는 스크롤을 멈추고 싶습니다.

3 단계에서 행을 아래로 스크롤하면 화면 맨 위의 두 섹션이 보이지 않게됩니다. 그런 다음 행의 별을 터치하여 새 즐겨 ​​찾기를 추가하면이 행이 섹션 2 인 즐겨 찾기 섹션에 삽입됩니다. 그러나 삽입을 수행 할 때 현재보기를 한 행 아래로 내립니다. 내가 즐겨 찾기 섹션을 볼 때 이것이 피할 수 없을 것이라고 이해하지만, 그 섹션이 화면에서 벗어나면 삽입으로 인해 내 행이 아래로 밀려 오는 것을보고 싶지 않습니다.

아래의 두 번째 이미지는 그 이상을 설명하는 데 도움이 될 수 있습니다. 여기서는 화면 아래로 스크롤했습니다. 별을 클릭하여 즐겨 찾기를 추가하면 섹션 2에 행을 삽입하고 해당 이미지에 표시되는 행을 한 행 아래로 푸시합니다. 위의 삽입 작업을 수행 할 때 해당 행을 그대로 유지하려고합니다.

나는 당신의 아이디어를 듣고 싶습니다. 감사.

enter image description here

enter image description here

답변

3

첫째, 같은 화면에서 사용자에게 표시 너무 많은 반복적 인 정보가없는 디자인을 고려하도록 촉구 -이 앱이보다 직관적 것 . 예를 들어, 선호하지 않는 행을 토글하는 옵션이 있습니다. 이렇게하면 모든 행을 표시하고 즐겨 찾기를 선택하거나 즐겨 찾기에서 선택 만하려는 경우 숨길 수 있습니다.

둘째,이 디자인을 유지하기로 결정한 경우 삽입으로 인한 스크롤을 중지하는 대신 새 행을 삽입하는 동안 테이블보기를 아래로 스크롤하는 것이 좋습니다. 사용자에게는 스크롤이 발생하지 않은 것으로 보입니다. 방법은 다음과 같습니다.

UITableView는 CGPoint 인 ContentOffset 속성을 가지고 있습니다. 이 점의 y 속성은 테이블 뷰가 스크롤되는 거리를 나타내는 CGFloat입니다. 당신이 행을 추가 할 때, 당신의 코드에서, 동시에 너무 화면을 아래로 스크롤 : 행이 선택되어있을 때 애니메이션을 사용하지 않는 경우

// I use some variables for illustrative purposes here (you will need to provide them from your existing code): 

// *** put your code to add or remove the row from favorites to your table view data source here *** 

// start animation queue 
[UIView beginAnimations:nil context:nil]; 
// check if a row is being added or deleted 
if (isAddingRow) { 
    // if added, call to insert the row into the table view 
    [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:insertedIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    // also tell the table view to scroll down the height of a row 
    [tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y + kHeightOfRow) animated:YES]; 
} else { 
    // if deleted, call to delete the row into the table view 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deletedIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    // also tell the table view to scroll down the height of a row 
    [tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y - kHeightOfRow) animated:YES]; 
} 
// launch animations 
[UIView commitAnimations]; 

다른 방법으로, 당신은 실제로 애니메이션을 해제 할 수 있습니다

() 어떤 애니메이션없이 위와 같은 작업을 수행합니다 애니메이션 :

// check if a row is being added or deleted 
if (isAddingRow) { 
    // if added, call to insert the row into the table view 
    [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:insertedIndexPath] withRowAnimation:UITableViewRowAnimationNone]; 
    // also tell the table view to scroll down the height of a row 
    [tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y + kHeightOfRow) animated:NO]; 
} else { 
    // if deleted, call to delete the row into the table view 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deletedIndexPath] withRowAnimation:UITableViewRowAnimationNone]; 
    // also tell the table view to scroll down the height of a row 
    [tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y - kHeightOfRow) animated:NO]; 
} 

당신은 또한 setContentOffset을 수행 할 수 있습니다 방법을 테이블 뷰 contentSize가있는 tableView 크기보다 큰) (또는 될 것입니다 경우에만 사용할 수 있습니다. 희망이 도움이됩니다!

관련 문제