本文介紹了檢查 UIScrollView 是否到達頂部或底部的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
有沒有辦法知道 UIScrollView
是到達頂部還是底部?可能在方法中:
Is there a way to know if a UIScrollView
has reached the top or bottom? Possibly in the method:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate
推薦答案
在你的類中實現(xiàn)UIScrollViewDelegate
,然后添加:
Implement the UIScrollViewDelegate
in your class, and then add this:
-(void)scrollViewDidScroll: (UIScrollView*)scrollView
{
float scrollViewHeight = scrollView.frame.size.height;
float scrollContentSizeHeight = scrollView.contentSize.height;
float scrollOffset = scrollView.contentOffset.y;
if (scrollOffset == 0)
{
// then we are at the top
}
else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
{
// then we are at the end
}
}
希望這就是你所追求的!否則,通過在上面的代碼中添加更多條件和 NSLog 滾動偏移的值來進行修補.
Hope this is what you are after! Else have a tinker by adding more conditions to the above code and NSLog the value of scrollOffset.
這篇關于檢查 UIScrollView 是否到達頂部或底部的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!