簡體   English   中英

在UITableView中,我如何知道某行的scrollRectToVisible何時完成?

[英]In a UITableView, how do I know when scrollRectToVisible is complete for a row?

當我在UITableView中選擇一行時,我正在調用scrollRectToVisible:animated在行的幀的GCRect上進行scrollRectToVisible:animated處理,然后立即執行其他動畫。 我的問題是我不知道來自scrollRectToVisible:animated的動畫何時完成。

我的代碼:

- (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! 
}

我遇到了這個UIScrollViewDelegate方法:

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

只調用動畫卷軸。 不要求基於觸摸的滾動。 似乎工作得很好。

更簡單的方法是將滾動代碼封裝在UIView animateWith [...]塊中,如下所示:

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

請注意,scrollRectToVisible:animated:方法中的動畫== NO。

協議UITableViewDelegate符合UIScrollViewDelegate 手動滾動時可以設置BOOL參數,而不是在scrollViewDidScroll:檢查它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
    }

}

別忘了設置UITableViewDelegate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM