Permalink
Browse files

Use -layoutSubviews to modify the position to make infinite scrolling…

… work. Closes #5.
  • Loading branch information...
1 parent 419d60e commit 1d60af9affb677abdea3259896a6df915917009c @danielctull committed Dec 15, 2010
Showing with 21 additions and 20 deletions.
  1. +1 −5 DTInfiniteGridView/DTInfiniteGridView.h
  2. +20 −15 DTInfiniteGridView/DTInfiniteGridView.m
@@ -10,15 +10,11 @@
#import "DTGridView.h"
-@interface DTInfiniteGridView : DTGridView {
- BOOL infiniteVerticalScrolling, infiniteHorizontalScrolling;
-
+@interface DTInfiniteGridView : DTGridView {
NSInteger fakeNumberOfRows;
- //NSMutableArray *numberOfColumns;
NSMutableDictionary *numberOfColumns;
NSInteger segmentMultiplier;
-
}
@property (nonatomic, assign) BOOL infiniteVerticalScrolling, infiniteHorizontalScrolling;
@@ -90,30 +90,35 @@ - (DTGridViewCell *)findViewForRow:(NSInteger)row column:(NSInteger)column {
}
-- (void)positionCheck {
-
- if (!self.infiniteHorizontalScrolling && !self.infiniteVerticalScrolling)
- return;
-
- CGFloat segmentWidth = self.contentSize.width/5;
-
- //CGFloat twotimes = 2*segmentWidth;
+- (void)layoutSubviews {
CGFloat newX = self.contentOffset.x;
CGFloat newY = self.contentOffset.y;
- //NSLog(@"%s:%f %f", _cmd, segmentWidth, self.contentOffset.x);
+ if (self.infiniteHorizontalScrolling) {
+
+ CGFloat segmentWidth = self.contentSize.width/5;
+
+ if (self.contentOffset.x < 2*segmentWidth)
+ newX = self.contentOffset.x + segmentWidth;
+ else if (self.contentOffset.x > 3*segmentWidth)
+ newX = self.contentOffset.x - segmentWidth;
+ }
+
- if (self.contentOffset.x < 2*segmentWidth)
- newX = self.contentOffset.x + segmentWidth;
- else if (self.contentOffset.x > 3*segmentWidth)
- newX = self.contentOffset.x - segmentWidth;
+ if (self.infiniteVerticalScrolling) {
- //NSLog(@"%s:%f", _cmd, newX);
+ CGFloat segmentHeight = self.contentSize.height/5;
+ if (self.contentOffset.y < 2*segmentHeight)
+ newY = self.contentOffset.y + segmentHeight;
+ else if (self.contentOffset.y > 3*segmentHeight)
+ newY = self.contentOffset.y - segmentHeight;
+ }
+
self.contentOffset = CGPointMake(newX, newY);
-
+ [super layoutSubviews];
}
@end

0 comments on commit 1d60af9

Please sign in to comment.