2012-03-29 13 views
8

Po wybraniu wiersza w widoku UITableView wywołuję scrollRectToVisible:animated w GCRect w ramce wiersza i natychmiast po wykonaniu innych animacji. Mój problem polega na tym, że nie wiem, kiedy animacja z scrollRectToVisible:animated została ukończona.W UITableView, skąd mam wiedzieć, kiedy scrollRectToVisible jest kompletny dla wiersza?

Mój kod:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRwoAtIndexPath:indexPath]; 

    [self.tableView scrollRectToVisible:cell.frame animated:YES]; 

    //more animations here, which I'd like to start only after the previous line is finished! 
} 
+0

+1 Dobre pytanie, ale obawiam się, że odpowiedź brzmi: nie wiesz, kiedy "scrollRectToVisible: animated:" kończy. – Sam

+0

Odpowiedź na następujące pytanie może pomóc również tutaj: http://stackoverflow.com/questions/7198633/how-can-i-tell-when-a-uitableview-animation-has-finished – fishinear

Odpowiedz

3

Protokół UITableViewDelegate zgodny UIScrollViewDelegate. Można ustawić BOOL parametr podczas przewijania i ręcznie niż sprawdzić w scrollViewDidScroll:

BOOL manualScroll; 
... 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRwoAtIndexPath:indexPath]; 

    manualScroll = YES; 
    [self.tableView scrollRectToVisible:cell.frame animated:YES]; 
} 
... 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    if (manualScroll) 
    { 
     manualScroll = NO; 
     //Do your staff 
    } 

} 

Nie zapomnij ustawić UITableViewDelegate.

+0

To jest dość hacky, ale wygląda na to, że to zadziała, i najlepsze, co możesz zrobić, biorąc pod uwagę ramy. Dziękuję za odpowiedź! –

+0

jest właściwość 'przeciągania' na UIScrollView, która wykonuje ręczne śledzenie ruchu dla ciebie –

15

natknąłem tej metody UIScrollViewDelegate:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView 
{ 
    // Do your stuff. 
} 

wywoływana tylko dla animowanych zwoje. Nie jest wywoływany do przewijania za pomocą dotyku. Wydaje się działać świetnie.

+0

Właśnie tego szukałem, dziękuję !! –

5

Łatwiejszy sposób jest do hermetyzacji kodu przewijania w UIView animateWith [...] bloku tak:

[UIView animateWithDuration:0.3f animations:^{ 
    [self.tableView scrollRectToVisible:cell.frame animated:NO]; 
} completion:^(BOOL finished) { 
    // Some completion code 
}]; 

Zauważ, że animowane == NO w scrollRectToVisible: animowany: metoda.

+0

To powinien być użytkownik poczty –

Powiązane problemy