文章轉自:http://blog.csdn.net/z343929897/article/details/8106408
- contentSize:CGSize類型,scrollview可以滑動的區域,例如,一個view的frame爲(0,0,320,480),而scrollview的contentSize爲(320,1080),則表示scrollView的垂直滑動區域爲整個屏幕的3倍。
- contentView:scrollview的內容顯示區域,一般情況下和scrollview的contentsize保持一致。
- contentOffset:CGPoint類型,它表示scrollView當前的顯示區域頂點相對於frame頂點的偏移量,如在上面的例子中,如果某一時刻contentOffset的值爲(0,960),就表示scrollview的偏移量爲(0,960)。
- contentInset:UIEdgeInsets類型,srollciew的contentView的頂點相對於scrollview的位置,它標識了contenView開始顯示的位置,這個屬性和css以及xaml中的margin屬性類似。
知道了上面幾個概念後,要判斷srollciew是否滑到底部就容易多了,代碼如下:
CGPoint offset = scrollView.contentOffset;
CGRect bounds = scrollView.bounds;
CGSize size = scrollView.contentSize;
UIEdgeInsets inset = scrollView.contentInset;
CGFloat currentOffset = offset.y + bounds.size.height – inset.bottom;
CGFloat maximumOffset = size.height;
當currentOffset與maximumOffset的值相等時,即說明scrollview已經滑到底部了。
同理,還可以根具上述兩個偏移量的差值實現當滑到某一區域時,做點其它什麼事,比如當滑到離底部還有50個像素的時候,在後臺加載更多的數據:
if((maximumOffset – currentOffset)<50.0)
NSLog(@”LoadMore…”);