[英]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.