Skip to content

Instantly share code, notes, and snippets.

@iRiziya
Last active April 16, 2016 09:15
Show Gist options
  • Save iRiziya/e682cbfa5250e9fa4e60 to your computer and use it in GitHub Desktop.
Save iRiziya/e682cbfa5250e9fa4e60 to your computer and use it in GitHub Desktop.
Option 1 :
override func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
let offset:CGPoint = scrollView.contentOffset;
let bounds:CGRect = scrollView.bounds;
let size:CGSize = scrollView.contentSize;
let inset:UIEdgeInsets = scrollView.contentInset;
let y:CGFloat = offset.y + bounds.size.height - inset.bottom;
let h:CGFloat = size.height;
let reload_distance:CGFloat = 30;
if(y < h + reload_distance) {
print("At top : load older data")
}
if(y > h + reload_distance) {
print("At bottom : load more(newer) data")
}
}
Reference : http://stackoverflow.com/a/17860149/3734028
Option 2 :
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
// UITableView only moves in one direction, y axis
CGFloat currentOffset = scrollView.contentOffset.y;
CGFloat maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
if (maximumOffset - currentOffset <= 20.0) {
[self getMessages];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment