UIScrollView+VTMagic.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // UIScrollView+VTMagic.m
  3. // VTMagic
  4. //
  5. // Created by tianzhuo on 15/7/9.
  6. // Copyright (c) 2015年 tianzhuo. All rights reserved.
  7. //
  8. #import "UIScrollView+VTMagic.h"
  9. @implementation UIScrollView (VTMagic)
  10. - (BOOL)vtm_isNeedDisplayWithFrame:(CGRect)frame preloading:(BOOL)preloading {
  11. CGRect visibleRect = (CGRect){CGPointMake(self.contentOffset.x, 0), self.frame.size};
  12. CGRect intersectRegion = CGRectIntersection(frame, visibleRect);
  13. BOOL isOnScreen = !CGRectIsNull(intersectRegion) || !CGRectIsEmpty(intersectRegion);
  14. if (!preloading) {
  15. BOOL isNotBorder = 0 != (int)self.contentOffset.x%(int)self.frame.size.width;
  16. return isOnScreen && (isNotBorder ?: 0 != intersectRegion.size.width);
  17. }
  18. return isOnScreen;
  19. }
  20. - (BOOL)vtm_isItemNeedDisplayWithFrame:(CGRect)frame {
  21. frame.size.width *= 2;
  22. BOOL isOnScreen = [self vtm_isNeedDisplayWithFrame:frame preloading:YES];
  23. if (isOnScreen) {
  24. return YES;
  25. }
  26. frame.size.width *= 0.5;
  27. frame.origin.x -= frame.size.width;
  28. isOnScreen = [self vtm_isNeedDisplayWithFrame:frame preloading:YES];
  29. return isOnScreen;
  30. }
  31. @end