2012-03-29 6 views
8

私はUITableViewで行を選択すると、行のフレームのGCRectにscrollRectToVisible:animatedを呼び出しています。その直後に他のアニメーションをいくつか実行しています。私の問題は、scrollRectToVisible:animatedのアニメーションがいつ完了したのか分かりません。UITableViewで、行のscrollRectToVisibleが完了したときはどうすればわかりますか?

マイコード:

- (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良い質問ですが、私は答えが恐ろしいです:あなたは 'scrollRectToVisible:animated:'が終わる時を知らない。 – Sam

+0

次の質問に対する答えもここで役立ちます。http://stackoverflow.com/questions/7198633/how-can-i-tell-when-a-uitableview-animation-has-finished – fishinear

答えて

3

UITableViewDelegateUIScrollViewDelegateに準拠したプロトコル。手動でスクロールするときは、BOOLパラメータを設定することができ、よりはUITableViewDelegateを設定することを忘れないでください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 
    } 

} 

でそれを確認してください。

+0

これはかなりハッキーですが、それがうまくいくように思えますし、フレームワークを与えられれば最高のことができます。答えをありがとう! –

+0

UIScrollViewに 'dragging'プロパティがあり、手動スクロールトラッキングを行います –

15

私はこのUIScrollViewDelegate方法に出くわしました:のみアニメーションスクロールを呼びかけ

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

。タッチベースのスクロールでは呼び出されません。偉大な仕事をしているようだ。

+0

私が探していたもの、ありがとうございました! –

5

簡単な方法は次のように、ブロック[...]のUIView animateWithにおけるスクロールコードをカプセル化することである:でscrollRectToVisibleでNO ==アニメーション

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

注:アニメーション:方法。

+0

これはanwserである必要があります –

関連する問題