UIScrollView+Category.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // UIScrollView+Category.m
  3. // Blaufuchslive
  4. //
  5. // Created by 小凯 on 2020/3/9.
  6. // Copyright © 2020 刘惠萍. All rights reserved.
  7. //
  8. #import "UIScrollView+Category.h"
  9. @implementation UIScrollView (Category)
  10. //scroll did scroll block with linkSC
  11. - (void)scrollLink:(LinkScrollView*)linkSC{
  12. if (self.contentOffset.y <= 0) {
  13. if ([linkSC isKindOfClass:[LinkScrollView class]]) {
  14. if (linkSC.contentOffset.y > 0) {
  15. linkSC.contentOffset = CGPointMake(linkSC.contentOffset.x, linkSC.contentOffset.y + self.contentOffset.y);
  16. self.contentOffset = CGPointMake(self.contentOffset.x, 0);
  17. }else{
  18. linkSC.contentOffset = CGPointMake(linkSC.contentOffset.x, 0);
  19. }
  20. }
  21. } else {
  22. //shang
  23. if ([linkSC isKindOfClass:[LinkScrollView class]]) {
  24. if (linkSC.contentOffset.y < linkSC.sizeHeight) {
  25. linkSC.contentOffset = CGPointMake(linkSC.contentOffset.x, linkSC.contentOffset.y + self.contentOffset.y);
  26. self.contentOffset = CGPointMake(self.contentOffset.x, 0);
  27. if (linkSC.contentOffset.y > linkSC.sizeHeight) {
  28. linkSC.contentOffset = CGPointMake(linkSC.contentOffset.x, ceilf(linkSC.sizeHeight));
  29. }
  30. }
  31. }
  32. }
  33. }
  34. //scroll to bottom
  35. - (void)scrollToBottom:(BOOL)animated
  36. {
  37. if (self.contentSize.height + self.contentInset.bottom > self.frame.size.height)
  38. {
  39. CGPoint offset = CGPointMake(0, self.contentSize.height + self.contentInset.bottom - self.bounds.size.height);
  40. [self setContentOffset:offset animated:animated];
  41. }
  42. }
  43. @end