如何在scrollToRowAtIndexPath完成动画时获得通知 [英] How to get notified when scrollToRowAtIndexPath finishes animating
问题描述
This is a follow-up to How to get notified when a tableViewController finishes animating the push onto a nav stack.
在一个 tableView
In a tableView
I want to deselect a row with animation, but only after the tableView has finished animating the scroll to the selected row. How can I be notified when that happens, or what method gets called the moment that finishes.
这是事情的顺序:
- 推送视图控制器
- 在
viewWillAppear
li>
- 在
viewDidAppear
IscrollToRowAtIndexPath
- 然后,当完成滚动我想要
deselectRowAtIndexPath:animated:YES
- Push view controller
- In
viewWillAppear
I select a certain row. - In
viewDidAppear
IscrollToRowAtIndexPath
(to the selected row). - Then when that finishes scrolling I want to
deselectRowAtIndexPath: animated:YES
这样,用户将知道为什么它们在那里滚动,但是我可以淡化选择。
第4步是我还没有找到的部分。如果我在 viewDidAppear
中调用它,则在tableView在那里滚动的时候,该行已经被取消选择了,这是不好的。
This way, the user will know why they were scrolled there, but then I can fade away the selection.
Step 4 is the part I haven't figured out yet. If I call it in viewDidAppear
then by the time the tableView scrolls there, the row has been deselected already which is no good.
推荐答案
您可以使用表视图委托的 scrollViewDidEndScrollingAnimation:
方法。这是因为 UITableView
是 UIScrollView
和 UITableViewDelegate
符合 UIScrollViewDelegate
。换句话说,一个表视图是一个滚动视图,一个表视图委托也是一个滚动视图委托。
You can use the table view delegate's scrollViewDidEndScrollingAnimation:
method. This is because a UITableView
is a subclass of UIScrollView
and UITableViewDelegate
conforms to UIScrollViewDelegate
. In other words, a table view is a scroll view, and a table view delegate is also a scroll view delegate.
所以,创建一个 scrollViewDidEndScrollingAnimation :
方法,并取消选择该方法中的单元格。有关 scrollViewDidEndScrollingAnimation:
方法的信息,请参阅 UIScrollViewDelegate
的参考文档。
So, create a scrollViewDidEndScrollingAnimation:
method in your table view delegate and deselect the cell in that method. See the reference documentation for UIScrollViewDelegate
for information on the scrollViewDidEndScrollingAnimation:
method.
这篇关于如何在scrollToRowAtIndexPath完成动画时获得通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!