問題描述
我有一個(gè) UIScrollView,我在上面調(diào)用 scrollRectToVisible:animated:YES.我想設(shè)置動(dòng)畫的速度.可以嗎?
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?
推薦答案
我最終找到了解決方案.就我而言,滾動(dòng)在啟動(dòng)后以編程方式進(jìn)行動(dòng)畫處理,以模仿老虎機(jī)(帶有 3 個(gè)水平 UIScrollView).正在使用 scrollRectToVisible:animated: 方法執(zhí)行此操作.
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 設(shè)置自定義速度:
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 取決于滾動(dòng)條在每個(gè)繪圖"之間移動(dòng)的距離.
AnimationDuration depends on the distance the scroller has to move between each "drawing".
這篇關(guān)于UIScrollView scrollRectToVisible 以自定義速度的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!