問題描述
有沒有辦法取消 UIScrollView 的減速?
Is there a way to deactivate the decelerating of a UIScrollView?
我想允許用戶滾動(dòng)畫布,但我不希望用戶抬起手指后畫布繼續(xù)滾動(dòng).
I want to allow the user to scroll the canvas, but I don't want that the canvas continues scrolling after the user lifted the finger.
推薦答案
這可以通過利用 UIScrollView
委托方法 scrollViewWillBeginDecelerating
自動(dòng)設(shè)置內(nèi)容偏移量來完成當(dāng)前屏幕位置.
This can be done by utilizing the UIScrollView
delegate method scrollViewWillBeginDecelerating
to automatically set the content offset to the current screen position.
實(shí)施:
- 如果您還沒有這樣做,請為您的
UIScrollView
對象分配一個(gè)委托. 在您的委托的
.m
實(shí)現(xiàn)文件中,添加以下代碼行:
- Assign a delegate to your
UIScrollView
object if you have not already done so. In your delegate's
.m
implementation file, add the following lines of code:
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
[scrollView setContentOffset:scrollView.contentOffset animated:YES];
}
瞧!不再自動(dòng)滾動(dòng).
這篇關(guān)于停用 UIScrollView 減速的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!