問題描述
我有一個 UIScrollView,我在上面調用 scrollRectToVisible:animated:YES.我想設置動畫的速度.可以嗎?
I have a UIScrollView and I'm calling scrollRectToVisible:animated:YES on it. I would like to set the speed at which it is animated. Can that be done?
推薦答案
我最終找到了解決方案.就我而言,滾動在啟動后以編程方式進行動畫處理,以模仿老虎機(帶有 3 個水平 UIScrollView).正在使用 scrollRectToVisible:animated: 方法執行此操作.
I ended up finding a solution. In my case, the scrolling was animated programmatically after launch, to mimic a slot machine (with 3 horizontal UIScrollViews). Was doing this with the scrollRectToVisible:animated: method.
我必須使用 UIView 的 beginAnimation 設置自定義速度:
I got to set a custom speed using UIView's beginAnimation:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:(abs(rMid-pMid)*0.3)];
scrollMid.contentOffset = CGPointMake(rMid*320, 0);
[UIView commitAnimations];
AnimationDuration 取決于滾動條在每個繪圖"之間移動的距離.
AnimationDuration depends on the distance the scroller has to move between each "drawing".
這篇關于UIScrollView scrollRectToVisible 以自定義速度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!