<UIScrollViewDelegate >
@property (nonatomic, assign) NSInteger lastcontentOffset; //添加此屬性的作用,依據差值,判別ScrollView是上滑還是下拉
self.collectionView.delegate = self;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat hight = scrollView.frame.size.height;
CGFloat contentOffset = scrollView.contentOffset.y;
CGFloat distanceFromBottom = scrollView.contentSize.height - contentOffset;
CGFloat offset = contentOffset - self.lastcontentOffset;
self.lastcontentOffset = contentOffset;
if (offset > 0 && contentOffset > 0) {
NSLog(@"上拉行為");
}
if (offset < 0 && distanceFromBottom > hight) {
NSLog(@"下拉行為");
}
if (contentOffset == 0) {
NSLog(@"滑動到頂部");
}
if (distanceFromBottom < hight) {
NSLog(@"滑動究竟部");
}
}
【iOS開發:判別UIScrollView是上拉還是下拉】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!