Skip to content

Commit

Permalink
Comments and minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gmoledina committed Oct 24, 2011
1 parent 087c37f commit 2152ec9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 66 deletions.
16 changes: 9 additions & 7 deletions GMGridView/API/GMGridView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,24 @@ typedef enum

}

// Delegates
@property (nonatomic, weak) id<GMGridViewDataSource> dataSource;
@property (nonatomic, weak) id<GMGridViewSortingDelegate> sortingDelegate;
@property (nonatomic, weak) id<GMGridViewTransformationDelegate> transformDelegate;

@property (nonatomic, assign) NSInteger itemPadding;
@property (nonatomic, assign) BOOL centerGrid;
@property (nonatomic, assign) GMGridViewStyle style;
@property (nonatomic) CFTimeInterval minimumPressDuration; // If set to 0, the scrollView will not be scrollable
// Customizing Options
@property (nonatomic) GMGridViewStyle style; // Default is GMGridViewStyleSwap
@property (nonatomic) NSInteger itemPadding; // Default is 10
@property (nonatomic) BOOL centerGrid; // Default is YES
@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

// Actions
- (void)reloadData;
- (void)insertObjectAtIndex:(NSInteger)index;
- (void)removeObjectAtIndex:(NSInteger)index;
- (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2;
- (void)reloadObjectAtIndex:(NSInteger)index;
- (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2;

@end

Expand Down Expand Up @@ -114,6 +118,4 @@ typedef enum
- (void)GMGridView:(GMGridView *)gridView didEnterFullSizeForView:(UIView *)view;
- (void)GMGridView:(GMGridView *)gridView didEndTransformingView:(UIView *)view;



@end
36 changes: 24 additions & 12 deletions GMGridView/API/GMGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ @implementation GMGridView
@synthesize style = _style;
@synthesize minimumPressDuration;
@synthesize centerGrid;
@synthesize showFullSizeViewWithAlphaWhenTransforming;

@synthesize cacheStatusIsValid;
@synthesize itemSubviewsCache;
Expand Down Expand Up @@ -154,6 +155,9 @@ - (id)initWithFrame:(CGRect)frame
_tapGesture.numberOfTouchesRequired = 1;
[_scrollView addGestureRecognizer:_tapGesture];


// Transformation gestures :

_pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureUpdated:)];
_pinchGesture.delegate = self;
[_scrollView addGestureRecognizer:_pinchGesture];
Expand All @@ -168,7 +172,8 @@ - (id)initWithFrame:(CGRect)frame
[_panGesture setMinimumNumberOfTouches:2];
[_scrollView addGestureRecognizer:_panGesture];

// Sorting gestures
// Sorting gestures :

_sortingPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(sortingPanGestureUpdated:)];
_sortingPanGesture.delegate = self;
[_scrollView addGestureRecognizer:_sortingPanGesture];
Expand All @@ -177,13 +182,15 @@ - (id)initWithFrame:(CGRect)frame
_sortingLongPressGesture.numberOfTouchesRequired = 1;
[_scrollView addGestureRecognizer:_sortingLongPressGesture];


// Gesture dependencies
[_scrollView.panGestureRecognizer setMaximumNumberOfTouches:1];
[_scrollView.panGestureRecognizer requireGestureRecognizerToFail:_sortingPanGesture];

self.itemPadding = 10;
self.style = GMGridViewStylePush;
self.style = GMGridViewStyleSwap;
self.minimumPressDuration = 0.2;
self.showFullSizeViewWithAlphaWhenTransforming = YES;

_sortFuturePosition = GMGV_INVALID_POSITION;
_itemSize = CGSizeZero;
Expand Down Expand Up @@ -318,9 +325,9 @@ - (void)sortingLongPressGestureUpdated:(UILongPressGestureRecognizer *)longPress
{
[self sortingMoveDidStartAtPoint:location];
}

break;
}

case UIGestureRecognizerStateEnded:
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed:
Expand All @@ -330,9 +337,9 @@ - (void)sortingLongPressGestureUpdated:(UILongPressGestureRecognizer *)longPress
CGPoint location = [longPressGesture locationInView:_scrollView];
[self sortingMoveDidStopAtPoint:location];
}

break;
}

default:
break;
}
Expand Down Expand Up @@ -375,8 +382,6 @@ - (void)sortingPanGestureUpdated:(UIPanGestureRecognizer *)panGesture
}
}



- (void)sortingAutoScrollMovementCheck
{
if (_sortMovingItem && _autoScrollActive)
Expand Down Expand Up @@ -460,14 +465,16 @@ - (void)panGestureUpdated:(UIPanGestureRecognizer *)panGesture
case UIGestureRecognizerStateBegan:
{
[self transformingGestureDidBeginWithGesture:panGesture];

_scrollView.scrollEnabled = NO;

break;
}
case UIGestureRecognizerStateChanged:
{
CGPoint translate = [panGesture translationInView:_scrollView];
[_transformingItem setCenter:CGPointMake(_transformingItem.center.x + translate.x, _transformingItem.center.y + translate.y)];
[panGesture setTranslation:CGPointZero inView:_scrollView];

break;
}
default:
Expand All @@ -492,6 +499,8 @@ - (void)pinchGestureUpdated:(UIPinchGestureRecognizer *)pinchGesture
case UIGestureRecognizerStateBegan:
{
[self transformingGestureDidBeginWithGesture:pinchGesture];

break;
}
case UIGestureRecognizerStateChanged:
{
Expand All @@ -505,7 +514,7 @@ - (void)pinchGestureUpdated:(UIPinchGestureRecognizer *)pinchGesture

_lastScale = [_pinchGesture scale];

if ([_pinchGesture scale] >= 1.5)
if (self.showFullSizeViewWithAlphaWhenTransforming && [_pinchGesture scale] >= 1.5)
{
[_transformingItem stepToFullsizeWithAlpha:1 - (2.5 - [_pinchGesture scale])];
}
Expand Down Expand Up @@ -535,6 +544,8 @@ - (void)rotationGestureUpdated:(UIRotationGestureRecognizer *)rotationGesture
case UIGestureRecognizerStateBegan:
{
[self transformingGestureDidBeginWithGesture:rotationGesture];

break;
}
case UIGestureRecognizerStateChanged:
{
Expand All @@ -543,6 +554,7 @@ - (void)rotationGestureUpdated:(UIRotationGestureRecognizer *)rotationGesture
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);
_transformingItem.transform = newTransform;
_lastRotation = [rotationGesture rotation];

break;
}
default:
Expand Down Expand Up @@ -590,10 +602,11 @@ - (void)exitFullSizePinchGestureUpdated:(UIPinchGestureRecognizer *)pinchGesture
{
_inFullSizeMode = NO;
[_transformingItem removeGestureRecognizer:pinchGesture];

_transformingItem.frame = _transformingItem.fullSizeView.frame;

[self transformingGestureDidFinish];

break;
}
}
Expand Down Expand Up @@ -688,7 +701,7 @@ - (void)tapGestureUpdated:(UITapGestureRecognizer *)tapGesture

if (position != GMGV_INVALID_POSITION)
{
NSLog(@"Did tap at index %d", position);
NSLog(@"Did tap at index %d", position); // todo
}
}

Expand Down Expand Up @@ -1018,7 +1031,7 @@ - (NSArray *)itemSubviews
return subviews;
}

// TODO: validate if this method is used ( = viewWithTag)
// TODO: validate the use of this method ( = viewWithTag)
- (GMGridViewCell *)itemSubViewForPosition:(NSInteger)position
{
GMGridViewCell *view = nil;
Expand Down Expand Up @@ -1102,7 +1115,6 @@ - (CGSize)computeContentSize
{
return CGSizeMake(self.bounds.size.width - _scrollView.contentInset.left - _scrollView.contentInset.right,
ceil(_numberOfRowsInPage * (_itemSize.height + self.itemPadding) + self.itemPadding));

}

- (void)relayoutItems
Expand Down
8 changes: 4 additions & 4 deletions GMGridView/API/GMGridViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
@interface GMGridViewCell : UIView

@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, assign, getter=isInShakingMode) BOOL inShakingMode;

@property (nonatomic, strong) UIView *fullSizeView;
@property (nonatomic, assign) CGSize fullSize;
@property (nonatomic, assign, getter = isInFullSizeMode) BOOL inFullSizeMode;

@property (nonatomic, readonly, getter=isInShakingMode) BOOL inShakingMode;
@property (nonatomic, readonly, getter=isInFullSizeMode) BOOL inFullSizeMode;


- (id)initContentView:(UIView *)contentView;
- (void)shake:(BOOL)on;
- (void)shake:(BOOL)on; // shakes the contentView only, not the fullsize one

- (void)switchToFullSizeMode:(BOOL)fullSizeEnabled;
- (void)stepToFullsizeWithAlpha:(CGFloat)alpha;
Expand Down
22 changes: 4 additions & 18 deletions GMGridView/API/GMGridViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ - (void)layoutSubviews
}

//////////////////////////////////////////////////////////////
#pragma mark
#pragma mark Setters / getters
//////////////////////////////////////////////////////////////

- (void)setContentView:(UIView *)contentView
Expand Down Expand Up @@ -145,20 +145,6 @@ - (void)setFullSize:(CGSize)fullSize
}


//////////////////////////////////////////////////////////////
#pragma mark
//////////////////////////////////////////////////////////////

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/


//////////////////////////////////////////////////////////////
#pragma mark Public methods
//////////////////////////////////////////////////////////////
Expand All @@ -168,7 +154,7 @@ - (void)shake:(BOOL)on
if ((on && !self.inShakingMode) || (!on && self.inShakingMode))
{
[self.contentView shakeStatus:on];
self.inShakingMode = on;
_inShakingMode = on;
}
}

Expand All @@ -182,7 +168,7 @@ - (void)switchToFullSizeMode:(BOOL)fullSizeEnabled
self.fullSizeView.frame = CGRectMake(self.fullSizeView.frame.origin.x, self.fullSizeView.frame.origin.y, self.fullSize.width, self.fullSize.height);
self.fullSizeView.center = center;

self.inFullSizeMode = YES;
_inFullSizeMode = YES;

[UIView animateWithDuration:0.1
animations:^{
Expand All @@ -199,7 +185,7 @@ - (void)switchToFullSizeMode:(BOOL)fullSizeEnabled
{
self.fullSizeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

self.inFullSizeMode = NO;
_inFullSizeMode = NO;

[UIView animateWithDuration:0.1
animations:^{
Expand Down
2 changes: 1 addition & 1 deletion GMGridView/API/UIView+GMGridViewShake.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (void)shakeStatus:(BOOL)enabled

self.transform = CGAffineTransformMakeRotation(-1 * rotation);

[UIView beginAnimations:@"earthquake" context:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:MAXFLOAT];
[UIView setAnimationDuration:0.17];
Expand Down
27 changes: 5 additions & 22 deletions GMGridView/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
//

#import "AppDelegate.h"

#import "ViewController.h"

@implementation AppDelegate

@synthesize window = _window;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];

[self.window makeKeyAndVisible];
Expand All @@ -27,41 +24,27 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/

}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/

}

- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/

}

@end
2 changes: 1 addition & 1 deletion GMGridView/GMGridView-Prefix.pch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Prefix header for all source files of the 'DraggableGridView' target in the 'DraggableGridView' project
// Prefix header for all source files of the 'GMGridView' target in the 'GMGridView' project
//

#import <Availability.h>
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This view is inspired by the UITableView and uses a datasource and delegates in
Requirements:
- iOS 5 (to access the UIScrollView gestureRecognizers)
- ARC (Automatic Reference Counting)
- Frameworks Foundation, UIKit, CoreGraphics and QuartzCore
- Frameworks: Foundation, UIKit, CoreGraphics and QuartzCore

Features - General:
- Works on both the iPhone and iPad
Expand Down

0 comments on commit 2152ec9

Please sign in to comment.