Permalink
Browse files

Now inheriting from UIScrollView

  • Loading branch information...
1 parent bf2776e commit bbcb65d699c8ad057c2359e03a0543f80c3634ad @gmoledina committed Feb 1, 2012
Showing with 99 additions and 107 deletions.
  1. +3 −5 GMGridView/GMGridView.h
  2. +96 −102 GMGridView/GMGridView.m
View
8 GMGridView/GMGridView.h
@@ -61,7 +61,7 @@ typedef enum
#pragma mark Interface GMGridView
//////////////////////////////////////////////////////////////
-@interface GMGridView : UIView
+@interface GMGridView : UIScrollView
// Delegates
@property (nonatomic, gm_weak) IBOutlet NSObject<GMGridViewDataSource> *dataSource; // Required
@@ -84,10 +84,8 @@ typedef enum
@property (nonatomic) UIEdgeInsets minEdgeInsets; // Default is (5, 5, 5, 5)
@property (nonatomic) CFTimeInterval minimumPressDuration; // Default is 0.2; if set to 0, the scrollView will not be scrollable
@property (nonatomic) BOOL showFullSizeViewWithAlphaWhenTransforming; // Default is YES - not working right now
-@property (nonatomic) BOOL showsVerticalScrollIndicator; // Default is YES
-@property (nonatomic) BOOL showsHorizontalScrollIndicator; // Default is YES
-@property (nonatomic, readonly) UIScrollView *scrollView; // Messing with the scrollView can lead to unexpected behavior. Avoid changing any
- // properties or changing its delegate. You have been warned.
+
+@property (nonatomic, readonly) UIScrollView *scrollView __attribute__((deprecated)); // The grid now inherits directly from UIScrollView
// Reusable cells
- (GMGridViewCell *)dequeueReusableCell; // Should be called in GMGridView:cellForItemAtIndex: to reuse a cell
View
198 GMGridView/GMGridView.m
@@ -43,9 +43,6 @@
@interface GMGridView () <UIGestureRecognizerDelegate, UIScrollViewDelegate>
{
- // Views
- UIScrollView *_scrollView;
-
// Sorting Gestures
UIPanGestureRecognizer *_sortingPanGesture;
UILongPressGestureRecognizer *_sortingLongPressGesture;
@@ -146,7 +143,6 @@ @implementation GMGridView
@synthesize minEdgeInsets = _minEdgeInsets;
@synthesize showFullSizeViewWithAlphaWhenTransforming;
@synthesize editing = _editing;
-@synthesize scrollView = _scrollView;
@synthesize itemsSubviewsCacheIsValid = _itemsSubviewsCacheIsValid;
@synthesize itemSubviewsCache;
@@ -184,17 +180,11 @@ - (id)initWithCoder:(NSCoder *)aDecoder
- (void)commonInit
{
- _scrollView = [[UIScrollView alloc] initWithFrame:[self bounds]];
- _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- _scrollView.backgroundColor = [UIColor clearColor];
- _scrollView.delegate = self;
- [self addSubview:_scrollView];
-
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureUpdated:)];
_tapGesture.delegate = self;
_tapGesture.numberOfTapsRequired = 1;
_tapGesture.numberOfTouchesRequired = 1;
- [_scrollView addGestureRecognizer:_tapGesture];
+ [self addGestureRecognizer:_tapGesture];
/////////////////////////////
// Transformation gestures :
@@ -217,23 +207,23 @@ - (void)commonInit
_sortingPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(sortingPanGestureUpdated:)];
_sortingPanGesture.delegate = self;
- [_scrollView addGestureRecognizer:_sortingPanGesture];
+ [self addGestureRecognizer:_sortingPanGesture];
_sortingLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(sortingLongPressGestureUpdated:)];
_sortingLongPressGesture.numberOfTouchesRequired = 1;
_sortingLongPressGesture.delegate = self;
- [_scrollView addGestureRecognizer:_sortingLongPressGesture];
+ [self addGestureRecognizer:_sortingLongPressGesture];
////////////////////////
// Gesture dependencies
UIPanGestureRecognizer *panGestureRecognizer = nil;
- if ([_scrollView respondsToSelector:@selector(panGestureRecognizer)]) // iOS5 only
+ if ([self respondsToSelector:@selector(panGestureRecognizer)]) // iOS5 only
{
- panGestureRecognizer = _scrollView.panGestureRecognizer;
+ panGestureRecognizer = self.panGestureRecognizer;
}
else
{
- for (UIGestureRecognizer *gestureRecognizer in _scrollView.gestureRecognizers)
+ for (UIGestureRecognizer *gestureRecognizer in self.gestureRecognizers)
{
if ([gestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")])
{
@@ -281,11 +271,15 @@ - (void)dealloc
#pragma mark Layout
//////////////////////////////////////////////////////////////
-- (void)applyWithoutAnimation:(void (^)(void))animations {
- [CATransaction begin];
- [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
- animations();
- [CATransaction commit];
+- (void)applyWithoutAnimation:(void (^)(void))animations
+{
+ if (animations)
+ {
+ [CATransaction begin];
+ [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
+ animations();
+ [CATransaction commit];
+ }
}
- (void)layoutSubviewsWithAnimation:(GMGridViewItemAnimation)animation
@@ -343,7 +337,7 @@ - (void)layoutSubviews
transition.duration = 0.25f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
- [_scrollView.layer addAnimation:transition forKey:@"rotationAnimation"];
+ [self.layer addAnimation:transition forKey:@"rotationAnimation"];
[self applyWithoutAnimation:^{
[self layoutSubviewsWithAnimation:GMGridViewItemAnimationNone];
@@ -390,7 +384,7 @@ - (void)setLayoutStrategy:(id<GMGridViewLayoutStrategy>)layoutStrategy
{
_layoutStrategy = layoutStrategy;
- _scrollView.pagingEnabled = [[self.layoutStrategy class] requiresEnablingPaging];
+ self.pagingEnabled = [[self.layoutStrategy class] requiresEnablingPaging];
[self setNeedsLayout];
}
@@ -447,36 +441,23 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated
}
}
-- (void)setShowsVerticalScrollIndicator:(BOOL)showsVerticalScroll
-{
- _scrollView.showsVerticalScrollIndicator = showsVerticalScroll;
-}
-
-- (BOOL)showsVerticalScrollIndicator
-{
- return _scrollView.showsVerticalScrollIndicator;
-}
-
-- (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
-{
- _scrollView.showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;
-}
-
-- (BOOL)showsHorizontalScrollIndicator
-{
- return _scrollView.showsHorizontalScrollIndicator;
-}
-
-
//////////////////////////////////////////////////////////////
-#pragma mark UIScrollView delegate
+#pragma mark UIScrollView delegate replacement
//////////////////////////////////////////////////////////////
-- (void)scrollViewDidScroll:(UIScrollView *)scrollView
+- (void)contentOffset:(CGPoint)contentOffset
{
- [self loadRequiredItems];
+ BOOL valueChanged = !CGPointEqualToPoint(contentOffset, self.contentOffset);
+
+ [super setContentOffset:contentOffset];
+
+ if (valueChanged)
+ {
+ [self loadRequiredItems];
+ }
}
+
//////////////////////////////////////////////////////////////
#pragma mark GestureRecognizer delegate
//////////////////////////////////////////////////////////////
@@ -489,11 +470,11 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
BOOL valid = YES;
- BOOL isScrolling = _scrollView.isDragging || _scrollView.isDecelerating;
+ BOOL isScrolling = self.isDragging || self.isDecelerating;
if (gestureRecognizer == _tapGesture)
{
- CGPoint locationTouch = [_tapGesture locationInView:_scrollView];
+ CGPoint locationTouch = [_tapGesture locationInView:self];
valid = !isScrolling && !self.isEditing && [self.layoutStrategy itemPositionFromLocation:locationTouch] != GMGV_INVALID_POSITION;
}
else if (gestureRecognizer == _sortingLongPressGesture)
@@ -508,8 +489,8 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (self.transformDelegate != nil && [gestureRecognizer numberOfTouches] == 2)
{
- CGPoint locationTouch1 = [gestureRecognizer locationOfTouch:0 inView:_scrollView];
- CGPoint locationTouch2 = [gestureRecognizer locationOfTouch:1 inView:_scrollView];
+ CGPoint locationTouch1 = [gestureRecognizer locationOfTouch:0 inView:self];
+ CGPoint locationTouch2 = [gestureRecognizer locationOfTouch:1 inView:self];
NSInteger positionTouch1 = [self.layoutStrategy itemPositionFromLocation:locationTouch1];
NSInteger positionTouch2 = [self.layoutStrategy itemPositionFromLocation:locationTouch2];
@@ -537,7 +518,7 @@ - (void)sortingLongPressGestureUpdated:(UILongPressGestureRecognizer *)longPress
{
if (!_sortMovingItem)
{
- CGPoint location = [longPressGesture locationInView:_scrollView];
+ CGPoint location = [longPressGesture locationInView:self];
NSInteger position = [self.layoutStrategy itemPositionFromLocation:location];
@@ -557,7 +538,7 @@ - (void)sortingLongPressGestureUpdated:(UILongPressGestureRecognizer *)longPress
if (_sortMovingItem)
{
- CGPoint location = [longPressGesture locationInView:_scrollView];
+ CGPoint location = [longPressGesture locationInView:self];
[self sortingMoveDidStopAtPoint:location];
}
@@ -588,9 +569,9 @@ - (void)sortingPanGestureUpdated:(UIPanGestureRecognizer *)panGesture
}
case UIGestureRecognizerStateChanged:
{
- CGPoint translation = [panGesture translationInView:_scrollView];
+ CGPoint translation = [panGesture translationInView:self];
CGPoint offset = translation;
- CGPoint locationInScroll = [panGesture locationInView:_scrollView];
+ CGPoint locationInScroll = [panGesture locationInView:self];
_sortMovingItem.transform = CGAffineTransformMakeTranslation(offset.x, offset.y);
[self sortingMoveDidContinueToPoint:locationInScroll];
@@ -607,10 +588,14 @@ - (void)sortingAutoScrollMovementCheck
if (_sortMovingItem && _autoScrollActive)
{
CGPoint locationInMainView = [_sortingPanGesture locationInView:self];
- CGPoint locationInScroll = [_sortingPanGesture locationInView:_scrollView];
+ locationInMainView = CGPointMake(locationInMainView.x - self.contentOffset.x,
+ locationInMainView.y -self.contentOffset.y
+ );
+
CGFloat threshhold = _itemSize.height;
- CGPoint offset = _scrollView.contentOffset;
+ CGPoint offset = self.contentOffset;
+ CGPoint locationInScroll = [_sortingPanGesture locationInView:self];
// Going down
if (locationInMainView.x + threshhold > self.bounds.size.width)
@@ -654,17 +639,17 @@ - (void)sortingAutoScrollMovementCheck
}
}
- if (offset.x != _scrollView.contentOffset.x || offset.y != _scrollView.contentOffset.y)
+ if (offset.x != self.contentOffset.x || offset.y != self.contentOffset.y)
{
[UIView animateWithDuration:kDefaultAnimationDuration
delay:0
options:kDefaultAnimationOptions
animations:^{
- _scrollView.contentOffset = offset;
+ self.contentOffset = offset;
}
completion:^(BOOL finished){
- _scrollView.contentOffset = offset;
+ self.contentOffset = offset;
if (_autoScrollActive)
{
@@ -688,10 +673,10 @@ - (void)sortingMoveDidStartAtPoint:(CGPoint)point
GMGridViewCell *item = [self cellForItemAtIndex:position];
- [_scrollView bringSubviewToFront:item];
+ [self bringSubviewToFront:item];
_sortMovingItem = item;
- CGRect frameInMainView = [_scrollView convertRect:_sortMovingItem.frame toView:self.mainSuperView];
+ CGRect frameInMainView = [self convertRect:_sortMovingItem.frame toView:self.mainSuperView];
[_sortMovingItem removeFromSuperview];
_sortMovingItem.frame = frameInMainView;
@@ -721,11 +706,11 @@ - (void)sortingMoveDidStopAtPoint:(CGPoint)point
_sortMovingItem.tag = _sortFuturePosition + kTagOffset;
- CGRect frameInScroll = [self.mainSuperView convertRect:_sortMovingItem.frame toView:_scrollView];
+ CGRect frameInScroll = [self.mainSuperView convertRect:_sortMovingItem.frame toView:self];
[_sortMovingItem removeFromSuperview];
_sortMovingItem.frame = frameInScroll;
- [_scrollView addSubview:_sortMovingItem];
+ [self addSubview:_sortMovingItem];
CGPoint newOrigin = [self.layoutStrategy originForItemAtPosition:_sortFuturePosition];
CGRect newFrame = CGRectMake(newOrigin.x, newOrigin.y, _itemSize.width, _itemSize.height);
@@ -782,7 +767,7 @@ - (void)sortingMoveDidContinueToPoint:(CGPoint)point
if ((v.tag == tag || (v.tag < tag && v.tag >= _sortFuturePosition + kTagOffset)) && v != _sortMovingItem )
{
v.tag = v.tag - 1;
- [_scrollView sendSubviewToBack:v];
+ [self sendSubviewToBack:v];
}
}
}
@@ -793,7 +778,7 @@ - (void)sortingMoveDidContinueToPoint:(CGPoint)point
if ((v.tag == tag || (v.tag > tag && v.tag <= _sortFuturePosition + kTagOffset)) && v != _sortMovingItem)
{
v.tag = v.tag + 1;
- [_scrollView sendSubviewToBack:v];
+ [self sendSubviewToBack:v];
}
}
}
@@ -849,14 +834,14 @@ - (void)panGestureUpdated:(UIPanGestureRecognizer *)panGesture
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(transformingGestureDidFinish) object:nil];
[self performSelector:@selector(transformingGestureDidFinish) withObject:nil afterDelay:0.1];
- _scrollView.scrollEnabled = YES;
+ self.scrollEnabled = YES;
break;
}
case UIGestureRecognizerStateBegan:
{
[self transformingGestureDidBeginWithGesture:panGesture];
- _scrollView.scrollEnabled = NO;
+ self.scrollEnabled = NO;
break;
}
@@ -867,9 +852,9 @@ - (void)panGestureUpdated:(UIPanGestureRecognizer *)panGesture
[panGesture end];
}
- CGPoint translate = [panGesture translationInView:_scrollView];
+ CGPoint translate = [panGesture translationInView:self];
[_transformingItem.contentView setCenter:CGPointMake(_transformingItem.contentView.center.x + translate.x, _transformingItem.contentView.center.y + translate.y)];
- [panGesture setTranslation:CGPointZero inView:_scrollView];
+ [panGesture setTranslation:CGPointZero inView:self];
break;
}
@@ -995,11 +980,11 @@ - (void)transformingGestureDidBeginWithGesture:(UIGestureRecognizer *)gesture
}
else if (!_transformingItem)
{
- CGPoint locationTouch = [gesture locationOfTouch:0 inView:_scrollView];
+ CGPoint locationTouch = [gesture locationOfTouch:0 inView:self];
NSInteger positionTouch = [self.layoutStrategy itemPositionFromLocation:locationTouch];
_transformingItem = [self cellForItemAtIndex:positionTouch];
- CGRect frameInMainView = [_scrollView convertRect:_transformingItem.frame toView:self.mainSuperView];
+ CGRect frameInMainView = [self convertRect:_transformingItem.frame toView:self.mainSuperView];
[_transformingItem removeFromSuperview];
_transformingItem.frame = self.mainSuperView.bounds;
@@ -1077,7 +1062,7 @@ - (void)transformingGestureDidFinish
CGPoint origin = [self.layoutStrategy originForItemAtPosition:position];
CGRect finalFrameInScroll = CGRectMake(origin.x, origin.y, _itemSize.width, _itemSize.height);
- CGRect finalFrameInSuperview = [_scrollView convertRect:finalFrameInScroll toView:self.mainSuperView];
+ CGRect finalFrameInSuperview = [self convertRect:finalFrameInScroll toView:self.mainSuperView];
[transformingView switchToFullSizeMode:NO];
transformingView.autoresizingMask = UIViewAutoresizingNone;
@@ -1095,7 +1080,7 @@ - (void)transformingGestureDidFinish
[transformingView removeFromSuperview];
transformingView.frame = finalFrameInScroll;
transformingView.contentView.frame = transformingView.bounds;
- [_scrollView addSubview:transformingView];
+ [self addSubview:transformingView];
transformingView.fullSizeView = nil;
_inFullSizeMode = NO;
@@ -1121,7 +1106,7 @@ - (void)transformingGestureDidFinish
- (void)tapGestureUpdated:(UITapGestureRecognizer *)tapGesture
{
- CGPoint locationTouch = [_tapGesture locationInView:_scrollView];
+ CGPoint locationTouch = [_tapGesture locationInView:self];
NSInteger position = [self.layoutStrategy itemPositionFromLocation:locationTouch];
if (position != GMGV_INVALID_POSITION)
@@ -1187,11 +1172,11 @@ - (NSArray *)itemSubviews
}
else
{
- @synchronized(_scrollView)
+ @synchronized(self)
{
NSMutableArray *itemSubViews = [[NSMutableArray alloc] initWithCapacity:_numberTotalItems];
- for (UIView * v in [_scrollView subviews])
+ for (UIView * v in [self subviews])
{
if ([v isKindOfClass:[GMGridViewCell class]])
{
@@ -1238,10 +1223,10 @@ - (void)recomputeSizeAnimated:(BOOL)animated
CGSize contentSize = [self.layoutStrategy contentSize];
_minPossibleContentOffset = CGPointMake(0, 0);
- _maxPossibleContentOffset = CGPointMake(contentSize.width - _scrollView.bounds.size.width + _scrollView.contentInset.right,
- contentSize.height - _scrollView.bounds.size.height + _scrollView.contentInset.bottom);
+ _maxPossibleContentOffset = CGPointMake(contentSize.width - self.bounds.size.width + self.contentInset.right,
+ contentSize.height - self.bounds.size.height + self.contentInset.bottom);
- BOOL shouldUpdateScrollviewContentSize = !CGSizeEqualToSize(_scrollView.contentSize, contentSize);
+ BOOL shouldUpdateScrollviewContentSize = !CGSizeEqualToSize(self.contentSize, contentSize);
if (shouldUpdateScrollviewContentSize)
{
@@ -1251,13 +1236,13 @@ - (void)recomputeSizeAnimated:(BOOL)animated
delay:0
options:kDefaultAnimationOptions
animations:^{
- _scrollView.contentSize = contentSize;
+ self.contentSize = contentSize;
}
completion:nil];
}
else
{
- _scrollView.contentSize = contentSize;
+ self.contentSize = contentSize;
}
}
@@ -1307,7 +1292,7 @@ - (void)relayoutItemsAnimated:(BOOL)animated
- (void)loadRequiredItems
{
- NSRange rangeOfPositions = [self.layoutStrategy rangeOfPositionsInBoundsFromOffset: _scrollView.contentOffset];
+ NSRange rangeOfPositions = [self.layoutStrategy rangeOfPositionsInBoundsFromOffset: self.contentOffset];
NSRange loadedPositionsRange = NSMakeRange(self.firstPositionLoaded, self.lastPositionLoaded - self.firstPositionLoaded);
// calculate new position range
@@ -1330,7 +1315,7 @@ - (void)loadRequiredItems
if (![self cellForItemAtIndex:positionToLoad])
{
GMGridViewCell *cell = [self newItemSubViewForPosition:positionToLoad];
- [_scrollView addSubview:cell];
+ [self addSubview:cell];
}
}
}
@@ -1339,7 +1324,7 @@ - (void)loadRequiredItems
- (void)cleanupUnseenItems
{
- NSRange rangeOfPositions = [self.layoutStrategy rangeOfPositionsInBoundsFromOffset: _scrollView.contentOffset];
+ NSRange rangeOfPositions = [self.layoutStrategy rangeOfPositionsInBoundsFromOffset: self.contentOffset];
GMGridViewCell *cell;
if (rangeOfPositions.location > self.firstPositionLoaded)
@@ -1349,7 +1334,6 @@ - (void)cleanupUnseenItems
cell = [self cellForItemAtIndex:i];
if(cell)
{
- //NSLog(@"Removing item at position %d", i);
[self queueReusableCell:cell];
[cell removeFromSuperview];
}
@@ -1366,7 +1350,6 @@ - (void)cleanupUnseenItems
cell = [self cellForItemAtIndex:i];
if(cell)
{
- //NSLog(@"Removing item at position %d", i);
[self queueReusableCell:cell];
[cell removeFromSuperview];
}
@@ -1427,11 +1410,13 @@ - (GMGridViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier
- (void)reloadData
{
- CGPoint previousContentOffset = _scrollView.contentOffset;
+ CGPoint previousContentOffset = self.contentOffset;
- [[self itemSubviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop){
- [(UIView *)obj removeFromSuperview];
- if ([obj isKindOfClass:[GMGridViewCell class]]) {
+ [[self itemSubviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop)
+ {
+ if ([obj isKindOfClass:[GMGridViewCell class]])
+ {
+ [(UIView *)obj removeFromSuperview];
[self queueReusableCell:(GMGridViewCell *)obj];
}
}];
@@ -1450,7 +1435,7 @@ - (void)reloadData
CGPoint newContentOffset = CGPointMake(MIN(_maxPossibleContentOffset.x, previousContentOffset.x), MIN(_maxPossibleContentOffset.y, previousContentOffset.y));
newContentOffset = CGPointMake(MAX(newContentOffset.x, _minPossibleContentOffset.x), MAX(newContentOffset.y, _minPossibleContentOffset.y));
- _scrollView.contentOffset = newContentOffset;
+ self.contentOffset = newContentOffset;
[self loadRequiredItems];
@@ -1468,7 +1453,7 @@ - (void)reloadObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimat
CGPoint origin = [self.layoutStrategy originForItemAtPosition:index];
cell.frame = CGRectMake(origin.x, origin.y, _itemSize.width, _itemSize.height);
cell.alpha = 0;
- [_scrollView addSubview:cell];
+ [self addSubview:cell];
currentView.tag = kTagOffset - 1;
BOOL shouldScroll = animation & GMGridViewItemAnimationScroll;
@@ -1499,12 +1484,12 @@ - (void)scrollToObjectAtIndex:(NSInteger)index atScrollPosition:(GMGridViewScrol
CGPoint origin = [self.layoutStrategy originForItemAtPosition:index];
CGRect targetRect;
- if (_scrollView.pagingEnabled)
+ if (self.pagingEnabled)
{
CGPoint originScroll = CGPointZero;
- CGSize pageSize = CGSizeMake(_scrollView.bounds.size.width - _scrollView.contentInset.left - _scrollView.contentInset.right,
- _scrollView.bounds.size.height - _scrollView.contentInset.top - _scrollView.contentInset.bottom);
+ CGSize pageSize = CGSizeMake(self.bounds.size.width - self.contentInset.left - self.contentInset.right,
+ self.bounds.size.height - self.contentInset.top - self.contentInset.bottom);
while (originScroll.x + pageSize.width < origin.x)
{
@@ -1548,7 +1533,7 @@ - (void)scrollToObjectAtIndex:(NSInteger)index atScrollPosition:(GMGridViewScrol
delay:0
options:kDefaultAnimationOptions
animations:^{
- [_scrollView scrollRectToVisible:targetRect animated:NO];
+ [self scrollRectToVisible:targetRect animated:NO];
}
completion:^(BOOL finished){
}
@@ -1571,7 +1556,7 @@ - (void)insertObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimat
oldView.tag = oldView.tag + 1;
}
- [_scrollView addSubview:cell];
+ [self addSubview:cell];
}
_numberTotalItems++;
@@ -1660,10 +1645,10 @@ - (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2
view2.frame = CGRectMake(view2Origin.x, view2Origin.y, _itemSize.width, _itemSize.height);
- CGRect visibleRect = CGRectMake(_scrollView.contentOffset.x,
- _scrollView.contentOffset.y,
- _scrollView.contentSize.width,
- _scrollView.contentSize.height);
+ CGRect visibleRect = CGRectMake(self.contentOffset.x,
+ self.contentOffset.y,
+ self.contentSize.width,
+ self.contentSize.height);
// Better performance animating ourselves instead of using animated:YES in scrollRectToVisible
BOOL shouldScroll = animation & GMGridViewItemAnimationScroll;
@@ -1688,4 +1673,13 @@ - (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2
}
+//////////////////////////////////////////////////////////////
+#pragma mark public methods
+//////////////////////////////////////////////////////////////
+
+- (UIScrollView *)scrollView
+{
+ return self;
+}
+
@end

6 comments on commit bbcb65d

@jk
jk commented on bbcb65d Feb 9, 2012

I bisected to this commit, which breaks my app. I'm not using GMGridView to fully fill its parent view. The GMGridViewCells scroll over and under any other UIViews within the same parentView. Did you do this on purpose?

@steipete

Awesome! I totally missed that commit!

@jk this change shouldn't break anything, if so it's a regression. You still are able to use GMGridView only in a part of the screen. Maybe you can send an example/post screenshots so we see the problem?

@jk
jk commented on bbcb65d Feb 9, 2012

I'm not convinced it's a regression because the current implementation has also a feature it gives the user a hint, that there are more cells if the user scrolls (it cuts the cell on the edge of the screen…).

I made you two screenshots, before and after this commit.

Before:
Before

After:
After

@steipete

So it just draws out of the grid frame? Have you tried enabling clipToBounds?

https://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html

@jk
jk commented on bbcb65d Feb 9, 2012

That's it. Looks like if I set »Clip Subviews« via IB it has no effect, but it works when set it programmatically. Thanks.

@steipete

Rule 1 in iOS Club: Don't use IB. ;)

Please sign in to comment.