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