Permalink
Browse files

Comments and minor cleanup

  • Loading branch information...
gmoledina committed Oct 24, 2011
1 parent 087c37f commit 2152ec9eaf042a99efd5183dc2215751bc40994c
@@ -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
@@ -114,6 +118,4 @@ typedef enum
- (void)GMGridView:(GMGridView *)gridView didEnterFullSizeForView:(UIView *)view;
- (void)GMGridView:(GMGridView *)gridView didEndTransformingView:(UIView *)view;
-
-
@end
@@ -126,6 +126,7 @@ @implementation GMGridView
@synthesize style = _style;
@synthesize minimumPressDuration;
@synthesize centerGrid;
+@synthesize showFullSizeViewWithAlphaWhenTransforming;
@synthesize cacheStatusIsValid;
@synthesize itemSubviewsCache;
@@ -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];
@@ -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];
@@ -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;
@@ -318,9 +325,9 @@ - (void)sortingLongPressGestureUpdated:(UILongPressGestureRecognizer *)longPress
{
[self sortingMoveDidStartAtPoint:location];
}
+
break;
}
-
case UIGestureRecognizerStateEnded:
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed:
@@ -330,9 +337,9 @@ - (void)sortingLongPressGestureUpdated:(UILongPressGestureRecognizer *)longPress
CGPoint location = [longPressGesture locationInView:_scrollView];
[self sortingMoveDidStopAtPoint:location];
}
+
break;
}
-
default:
break;
}
@@ -375,8 +382,6 @@ - (void)sortingPanGestureUpdated:(UIPanGestureRecognizer *)panGesture
}
}
-
-
- (void)sortingAutoScrollMovementCheck
{
if (_sortMovingItem && _autoScrollActive)
@@ -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:
@@ -492,6 +499,8 @@ - (void)pinchGestureUpdated:(UIPinchGestureRecognizer *)pinchGesture
case UIGestureRecognizerStateBegan:
{
[self transformingGestureDidBeginWithGesture:pinchGesture];
+
+ break;
}
case UIGestureRecognizerStateChanged:
{
@@ -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])];
}
@@ -535,6 +544,8 @@ - (void)rotationGestureUpdated:(UIRotationGestureRecognizer *)rotationGesture
case UIGestureRecognizerStateBegan:
{
[self transformingGestureDidBeginWithGesture:rotationGesture];
+
+ break;
}
case UIGestureRecognizerStateChanged:
{
@@ -543,6 +554,7 @@ - (void)rotationGestureUpdated:(UIRotationGestureRecognizer *)rotationGesture
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);
_transformingItem.transform = newTransform;
_lastRotation = [rotationGesture rotation];
+
break;
}
default:
@@ -590,10 +602,11 @@ - (void)exitFullSizePinchGestureUpdated:(UIPinchGestureRecognizer *)pinchGesture
{
_inFullSizeMode = NO;
[_transformingItem removeGestureRecognizer:pinchGesture];
-
+
_transformingItem.frame = _transformingItem.fullSizeView.frame;
[self transformingGestureDidFinish];
+
break;
}
}
@@ -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
}
}
@@ -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;
@@ -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
@@ -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;
@@ -102,7 +102,7 @@ - (void)layoutSubviews
}
//////////////////////////////////////////////////////////////
-#pragma mark
+#pragma mark Setters / getters
//////////////////////////////////////////////////////////////
- (void)setContentView:(UIView *)contentView
@@ -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
//////////////////////////////////////////////////////////////
@@ -168,7 +154,7 @@ - (void)shake:(BOOL)on
if ((on && !self.inShakingMode) || (!on && self.inShakingMode))
{
[self.contentView shakeStatus:on];
- self.inShakingMode = on;
+ _inShakingMode = on;
}
}
@@ -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:^{
@@ -199,7 +185,7 @@ - (void)switchToFullSizeMode:(BOOL)fullSizeEnabled
{
self.fullSizeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- self.inFullSizeMode = NO;
+ _inFullSizeMode = NO;
[UIView animateWithDuration:0.1
animations:^{
@@ -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];
View
@@ -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];
@@ -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
@@ -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>
View
2 README
@@ -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

0 comments on commit 2152ec9

Please sign in to comment.