[英]Flick a UIScrollView programmatically
當用戶在UIScrollView上進行輕彈手勢時,UIScrollView會獲得動量並開始移動,然后減速並最終停止。 但是我怎樣才能以編程方式實現這一目標? 我的意思是沒有手指輕彈,UIScrollView只是自動開始移動然后慢下來速度為0。
在我的應用程序中,我創建了我的UIScrollView,不像普通的UIScrollView(說它看起來像滾輪),所以我想向用戶提示他可以滾動它(然后一切都開始了!)
我搜索了很多,但似乎無法解決我的問題。 setContentOffset無法使自然“減速並停在前方某處”效果。
任何想法將不勝感激。
提前致謝。
嘗試,像這樣>
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:.8];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:(abs(1-3)*0.3)];
self.myScroll.contentOffset = CGPointMake(0, 500);
[UIView commitAnimations];
它目前不是您所需要的,但您可以自定義此代碼,並且可能一切正常)
或使用此代碼>
[UIView animateWithDuration:2.
delay:0.3
usingSpringWithDamping:1.
initialSpringVelocity:7.
options:UIViewAnimationOptionCurveEaseInOut animations:^{
//Animations
self.myScroll.contentOffset = CGPointMake(0, 500);
}
completion:^(BOOL finished) {
//Completion Block
}];
我認為這就像你想要的那樣(帶有阻尼效果的動畫,如滑動效果)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.