問題描述
我有一個使用 setContentOffset
自動滾動的 UITableView.像這樣:
I have a UITableView that I'm autoscrolling with setContentOffset
. Like so:
CGFloat point = self.table.tblMinutes.contentSize.height - self.table.tblMinutes.bounds.size.height;
[self.table.tblMinutes setContentOffset:CGPointMake(0, point) animated:false];
[self.table.tblMinutes layoutIfNeeded];
[UIView animateWithDuration:20.0 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
[self.table.tblMinutes setContentOffset:CGPointMake(0, point - 500) animated:false];
} completion:nil];
我想要實現的是滾動平穩地減速和停止.我無法做到這一點.
What I want to achieve is for the scrolling to smoothly slow down and stop. I haven't been able to achieve that.
調用 [self.table.tblMinutes.layer removeAllAnimations]
停止動畫,但由于某種原因移動了 contentOffset,沒有達到我想要的效果.
Calling [self.table.tblMinutes.layer removeAllAnimations]
stops the animation, but moves the contentOffset for some reason, not achieving what I want.
我嘗試在動畫中使用 UIViewAnimationOptionBeginFromCurrentState
選項,但沒有任何效果.
I tried using the UIViewAnimationOptionBeginFromCurrentState
option in a animation but that did nothing.
有什么建議嗎?
推薦答案
這是中斷現有動畫并將其替換為不同動畫的經典問題的子集.
This is a subset of the classic problem of interrupting an existing animation and replacing it with a different animation.
這里的問題是,如果你僅僅刪除現有的動畫,你會跳到那個動畫的結尾.
The problem here is that if you merely remove the existing animation, you will jump to the end of that animation.
解決方案是在移除現有動畫之前咨詢表示層并將層設置到該位置.現在您從中游開始,可以應用另一個動畫.
The solution to that is to consult the presentation layer and set the layer to that position before removing the existing animation. Now you are starting from midstream and can apply another animation.
這篇關于阻止 UITableView 自動滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!