Permalink
Browse files

Added mode demo content as examples.

  • Loading branch information...
1 parent 700c535 commit 74b9347a9bda6aa17bd02b73f544066283cf6fb4 @gmoledina committed Nov 11, 2011
View
18 GMGridView.xcodeproj/project.pbxproj
@@ -11,9 +11,10 @@
16026C131454631600093AFF /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 16026C111454631600093AFF /* LICENSE */; };
16026C141454631600093AFF /* README in Resources */ = {isa = PBXBuildFile; fileRef = 16026C121454631600093AFF /* README */; };
16275EF2144D26C10041AF02 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16275EF1144D26C10041AF02 /* QuartzCore.framework */; };
+ 16583C24146CC2290006F11B /* Demo2ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16583C23146CC2290006F11B /* Demo2ViewController.m */; };
1691D7A41442CFC300F472BF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1691D7A31442CFC300F472BF /* main.m */; };
1691D7AA1442D01F00F472BF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1691D7A71442D01F00F472BF /* AppDelegate.m */; };
- 1691D7AB1442D01F00F472BF /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1691D7A91442D01F00F472BF /* ViewController.m */; };
+ 1691D7AB1442D01F00F472BF /* Demo1ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1691D7A91442D01F00F472BF /* Demo1ViewController.m */; };
1691D7AE1442D02C00F472BF /* GMGridView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1691D7AD1442D02C00F472BF /* GMGridView.m */; };
16924B0C144156FE00E6E556 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16924B0B144156FE00E6E556 /* UIKit.framework */; };
16924B0E144156FE00E6E556 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16924B0D144156FE00E6E556 /* Foundation.framework */; };
@@ -30,13 +31,15 @@
16026C111454631600093AFF /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
16026C121454631600093AFF /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
16275EF1144D26C10041AF02 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ 16583C22146CC2290006F11B /* Demo2ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Demo2ViewController.h; path = GMGridView/Demo2ViewController.h; sourceTree = SOURCE_ROOT; };
+ 16583C23146CC2290006F11B /* Demo2ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Demo2ViewController.m; path = GMGridView/Demo2ViewController.m; sourceTree = SOURCE_ROOT; };
1691D7A01442CFA800F472BF /* GMGridView-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GMGridView-Info.plist"; path = "GMGridView/GMGridView-Info.plist"; sourceTree = SOURCE_ROOT; };
1691D7A21442CFC300F472BF /* GMGridView-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "GMGridView-Prefix.pch"; path = "GMGridView/GMGridView-Prefix.pch"; sourceTree = SOURCE_ROOT; };
1691D7A31442CFC300F472BF /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = GMGridView/main.m; sourceTree = SOURCE_ROOT; };
1691D7A61442D01F00F472BF /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = GMGridView/AppDelegate.h; sourceTree = SOURCE_ROOT; };
1691D7A71442D01F00F472BF /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = GMGridView/AppDelegate.m; sourceTree = SOURCE_ROOT; };
- 1691D7A81442D01F00F472BF /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ViewController.h; path = GMGridView/ViewController.h; sourceTree = SOURCE_ROOT; };
- 1691D7A91442D01F00F472BF /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ViewController.m; path = GMGridView/ViewController.m; sourceTree = SOURCE_ROOT; };
+ 1691D7A81442D01F00F472BF /* Demo1ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Demo1ViewController.h; path = GMGridView/Demo1ViewController.h; sourceTree = SOURCE_ROOT; };
+ 1691D7A91442D01F00F472BF /* Demo1ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Demo1ViewController.m; path = GMGridView/Demo1ViewController.m; sourceTree = SOURCE_ROOT; };
1691D7AC1442D02C00F472BF /* GMGridView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GMGridView.h; path = GMGridView/API/GMGridView.h; sourceTree = SOURCE_ROOT; };
1691D7AD1442D02C00F472BF /* GMGridView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = GMGridView.m; path = GMGridView/API/GMGridView.m; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
16924B07144156FE00E6E556 /* GMGridView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GMGridView.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -112,8 +115,10 @@
children = (
1691D7A61442D01F00F472BF /* AppDelegate.h */,
1691D7A71442D01F00F472BF /* AppDelegate.m */,
- 1691D7A81442D01F00F472BF /* ViewController.h */,
- 1691D7A91442D01F00F472BF /* ViewController.m */,
+ 1691D7A81442D01F00F472BF /* Demo1ViewController.h */,
+ 1691D7A91442D01F00F472BF /* Demo1ViewController.m */,
+ 16583C22146CC2290006F11B /* Demo2ViewController.h */,
+ 16583C23146CC2290006F11B /* Demo2ViewController.m */,
169AE3761460E1B300C0CBCD /* OptionsViewController.h */,
169AE3771460E1B300C0CBCD /* OptionsViewController.m */,
16924B12144156FE00E6E556 /* Supporting Files */,
@@ -215,13 +220,14 @@
files = (
1691D7A41442CFC300F472BF /* main.m in Sources */,
1691D7AA1442D01F00F472BF /* AppDelegate.m in Sources */,
- 1691D7AB1442D01F00F472BF /* ViewController.m in Sources */,
+ 1691D7AB1442D01F00F472BF /* Demo1ViewController.m in Sources */,
1691D7AE1442D02C00F472BF /* GMGridView.m in Sources */,
16A0D030145342F8004D7BBC /* GMGridViewCell.m in Sources */,
16026C0E1454628800093AFF /* UIView+GMGridViewAdditions.m in Sources */,
16DF1A6E145E3456006AA43C /* GMGridViewLayoutStrategies.m in Sources */,
16DF1A71145E3461006AA43C /* UIGestureRecognizer+GMGridViewAdditions.m in Sources */,
169AE3781460E1B300C0CBCD /* OptionsViewController.m in Sources */,
+ 16583C24146CC2290006F11B /* Demo2ViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
10 GMGridView/API/GMGridView.m
@@ -414,7 +414,7 @@ - (void)sortingAutoScrollMovementCheck
// Going down
if (locationInMainView.x + threshhold > self.bounds.size.width)
{
- offset.x += _itemSize.width;
+ offset.x += _itemSize.width / 2;
if (offset.x > _maxPossibleContentOffset.x)
{
@@ -424,7 +424,7 @@ - (void)sortingAutoScrollMovementCheck
// Going up
else if (locationInMainView.x - threshhold <= 0)
{
- offset.x -= _itemSize.width;
+ offset.x -= _itemSize.width / 2;
if (offset.x < _minPossibleContentOffset.x)
{
@@ -435,7 +435,7 @@ - (void)sortingAutoScrollMovementCheck
// Going right
if (locationInMainView.y + threshhold > self.bounds.size.height)
{
- offset.y += _itemSize.height;
+ offset.y += _itemSize.height / 2;
if (offset.y > _maxPossibleContentOffset.y)
{
@@ -445,7 +445,7 @@ - (void)sortingAutoScrollMovementCheck
// Going left
else if (locationInMainView.y - threshhold <= 0)
{
- offset.y -= _itemSize.height;
+ offset.y -= _itemSize.height / 2;
if (offset.y < _minPossibleContentOffset.y)
{
@@ -457,7 +457,7 @@ - (void)sortingAutoScrollMovementCheck
{
[UIView animateWithDuration:kDefaultAnimationDuration
delay:0
- options:kDefaultAnimationOptions
+ options:kDefaultAnimationOptions | UIViewAnimationOptionAllowUserInteraction
animations:^{
_scrollView.contentOffset = offset;
}
View
2 GMGridView/AppDelegate.h
@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
-@class ViewController;
+@class Demo1ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
View
13 GMGridView/AppDelegate.m
@@ -7,7 +7,9 @@
//
#import "AppDelegate.h"
-#import "ViewController.h"
+#import "Demo1ViewController.h"
+#import "Demo2ViewController.h"
+
@implementation AppDelegate
@@ -16,7 +18,14 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
+
+ UITabBarController *tabBarController = [[UITabBarController alloc] init];
+ [tabBarController setViewControllers:[NSArray arrayWithObjects:
+ [[UINavigationController alloc] initWithRootViewController:[[Demo1ViewController alloc] init]],
+ [[UINavigationController alloc] initWithRootViewController:[[Demo2ViewController alloc] init]],
+ nil]];
+
+ self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
View
2 GMGridView/ViewController.h → GMGridView/Demo1ViewController.h
@@ -8,6 +8,6 @@
#import <UIKit/UIKit.h>
-@interface ViewController : UIViewController
+@interface Demo1ViewController : UIViewController
@end
View
15 GMGridView/ViewController.m → GMGridView/Demo1ViewController.m
@@ -7,20 +7,18 @@
//
#import <QuartzCore/QuartzCore.h>
-#import "ViewController.h"
+#import "Demo1ViewController.h"
#import "GMGridView.h"
#import "OptionsViewController.h"
#define NUMBER_ITEMS_ON_LOAD 250
-#define INTERFACE_IS_PAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
-#define INTERFACE_IS_PHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
//////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark ViewController (privates methods)
//////////////////////////////////////////////////////////////
-@interface ViewController () <GMGridViewDataSource, GMGridViewSortingDelegate, GMGridViewTransformationDelegate>
+@interface Demo1ViewController () <GMGridViewDataSource, GMGridViewSortingDelegate, GMGridViewTransformationDelegate>
{
__weak GMGridView *_gmGridView;
UINavigationController *_optionsNav;
@@ -44,14 +42,14 @@ - (void)optionsDoneAction;
#pragma mark ViewController implementation
//////////////////////////////////////////////////////////////
-@implementation ViewController
+@implementation Demo1ViewController
- (id)init
{
if ((self =[super init]))
{
- self.title = @"GM-GridView";
+ self.title = @"Demo 1";
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addMoreItem)];
@@ -136,7 +134,7 @@ - (void)loadView
- (void)viewDidLoad
{
[super viewDidLoad];
- _gmGridView.mainSuperView = [UIApplication sharedApplication].keyWindow.rootViewController.view;
+ _gmGridView.mainSuperView = self.navigationController.view; //[UIApplication sharedApplication].keyWindow.rootViewController.view;
}
- (void)viewDidAppear:(BOOL)animated
@@ -374,7 +372,8 @@ - (void)refreshItem
- (void)presentInfo
{
- NSString *info = @"Long-press an item and its color will change; letting you know that you can now move it around.";
+ NSString *info = @"Long-press an item and its color will change; letting you know that you can now move it around. \n\nUsing two fingers, pinch/drag/rotate an item; zoom it enough and you will enter the fullsize mode";
+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Info"
message:info
delegate:nil
View
13 GMGridView/Demo2ViewController.h
@@ -0,0 +1,13 @@
+//
+// Demo2ViewController.h
+// GMGridView
+//
+// Created by Gulam Moledina on 11-11-10.
+// Copyright (c) 2011 GMoledina.ca. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface Demo2ViewController : UIViewController
+
+@end
View
395 GMGridView/Demo2ViewController.m
@@ -0,0 +1,395 @@
+//
+// Demo2ViewController.m
+// GMGridView
+//
+// Created by Gulam Moledina on 11-11-10.
+// Copyright (c) 2011 GMoledina.ca. All rights reserved.
+//
+
+#import <QuartzCore/QuartzCore.h>
+#import "Demo2ViewController.h"
+#import "GMGridView.h"
+#import "GMGridViewLayoutStrategies.h"
+#import "OptionsViewController.h"
+#import "OptionsViewController.h"
+
+@interface Demo2ViewController () <GMGridViewDataSource, GMGridViewSortingDelegate, GMGridViewTransformationDelegate>
+{
+ __weak GMGridView *_gmGridView1;
+ __weak GMGridView *_gmGridView2;
+
+ __weak UIButton *_buttonOptionsGrid1;
+ __weak UIButton *_buttonOptionsGrid2;
+
+ UIPopoverController *_popOverController;
+ UIViewController *_optionsController1;
+ UIViewController *_optionsController2;
+}
+
+- (void)computeViewFrames;
+- (void)showOptionsFromButton:(UIButton *)button;
+- (void)optionsDoneAction;
+
+@end
+
+
+//////////////////////////////////////////////////////////////
+#pragma mark -
+#pragma mark ViewController implementation
+//////////////////////////////////////////////////////////////
+
+@implementation Demo2ViewController
+
+
+- (id)init
+{
+ if ((self = [super init]))
+ {
+ self.title = @"Demo 2";
+ }
+ return self;
+}
+
+//////////////////////////////////////////////////////////////
+#pragma mark View lifecycle
+//////////////////////////////////////////////////////////////
+
+- (void)loadView
+{
+ [super loadView];
+ self.view.backgroundColor = [UIColor whiteColor];
+
+ GMGridView *gmGridView = [[GMGridView alloc] initWithFrame:self.view.bounds];
+ gmGridView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ gmGridView.style = GMGridViewStylePush;
+ gmGridView.itemSpacing = 5;
+ gmGridView.minEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
+ gmGridView.centerGrid = YES;
+ gmGridView.layoutStrategy = [GMGridViewLayoutStrategyFactory strategyFromType:GMGridViewLayoutVertical];
+ [self.view addSubview:gmGridView];
+ _gmGridView1 = gmGridView;
+
+ GMGridView *gmGridView2 = [[GMGridView alloc] initWithFrame:self.view.bounds];
+ gmGridView2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ gmGridView2.style = GMGridViewStylePush;
+ gmGridView2.itemSpacing = 5;
+ gmGridView2.minEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
+ gmGridView2.centerGrid = YES;
+ gmGridView2.layoutStrategy = [GMGridViewLayoutStrategyFactory strategyFromType:GMGridViewLayoutHorizontal];
+ [self.view addSubview:gmGridView2];
+ _gmGridView2 = gmGridView2;
+
+ _buttonOptionsGrid1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+ [_buttonOptionsGrid1 setTitle:@"Options Grid1" forState:UIControlStateNormal];
+ [_buttonOptionsGrid1 setReversesTitleShadowWhenHighlighted:YES];
+ [_buttonOptionsGrid1 sizeToFit];
+ _buttonOptionsGrid1.frame = CGRectMake(0, 0, _buttonOptionsGrid1.frame.size.width + 10, _buttonOptionsGrid1.frame.size.height + 10);
+ [_buttonOptionsGrid1 addTarget:self action:@selector(showOptionsFromButton:) forControlEvents:UIControlEventTouchUpInside];
+ [self.view addSubview:_buttonOptionsGrid1];
+
+ _buttonOptionsGrid2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+ [_buttonOptionsGrid2 setTitle:@"Options Grid2" forState:UIControlStateNormal];
+ [_buttonOptionsGrid2 setReversesTitleShadowWhenHighlighted:YES];
+ [_buttonOptionsGrid2 sizeToFit];
+ _buttonOptionsGrid2.frame = CGRectMake(0, 0, _buttonOptionsGrid2.frame.size.width + 10, _buttonOptionsGrid2.frame.size.height + 10);
+ [_buttonOptionsGrid2 addTarget:self action:@selector(showOptionsFromButton:) forControlEvents:UIControlEventTouchUpInside];
+ [self.view addSubview:_buttonOptionsGrid2];
+
+ [self computeViewFrames];
+}
+
+- (void)viewDidLayoutSubviews
+{
+ [self computeViewFrames];
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ _gmGridView1.sortingDelegate = self;
+ _gmGridView1.transformDelegate = self;
+ _gmGridView1.dataSource = self;
+
+ _gmGridView2.sortingDelegate = self;
+ _gmGridView2.transformDelegate = self;
+ _gmGridView2.dataSource = self;
+
+ _gmGridView1.mainSuperView = self.navigationController.view;
+ _gmGridView2.mainSuperView = self.navigationController.view;
+
+
+ OptionsViewController *optionsController = [[OptionsViewController alloc] init];
+ optionsController.gridView = _gmGridView1;
+ optionsController.contentSizeForViewInPopover = CGSizeMake(400, 500);
+ _optionsController1 = [[UINavigationController alloc] initWithRootViewController:optionsController];
+
+ OptionsViewController *optionsController2 = [[OptionsViewController alloc] init];
+ optionsController2.gridView = _gmGridView2;
+ optionsController2.contentSizeForViewInPopover = CGSizeMake(400, 500);
+ _optionsController2 = [[UINavigationController alloc] initWithRootViewController:optionsController2];
+
+ if (INTERFACE_IS_PHONE)
+ {
+ UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(optionsDoneAction)];
+ optionsController.navigationItem.rightBarButtonItem = doneButton;
+
+ UIBarButtonItem *doneButton2 = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(optionsDoneAction)];
+ optionsController2.navigationItem.rightBarButtonItem = doneButton2;
+ }
+}
+
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+}
+
+//////////////////////////////////////////////////////////////
+#pragma mark Controller events
+//////////////////////////////////////////////////////////////
+
+- (void)didReceiveMemoryWarning
+{
+ [super didReceiveMemoryWarning];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return YES;
+}
+
+//////////////////////////////////////////////////////////////
+#pragma mark Privates
+//////////////////////////////////////////////////////////////
+
+- (void)computeViewFrames
+{
+ CGSize itemSize = [self sizeForItemsInGMGridView:_gmGridView1];
+ CGSize minSize = CGSizeMake(itemSize.width + _gmGridView1.minEdgeInsets.right + _gmGridView1.minEdgeInsets.left,
+ itemSize.height + _gmGridView1.minEdgeInsets.top + _gmGridView1.minEdgeInsets.bottom);
+
+
+ CGRect frame1 = CGRectMake(10, 10, minSize.width, self.view.bounds.size.height - minSize.height - 30);
+ CGRect frame2 = CGRectMake(10, frame1.size.height + 20, self.view.bounds.size.width - 20 , minSize.height);
+
+ _gmGridView1.frame = frame1;
+ _gmGridView2.frame = frame2;
+
+ _buttonOptionsGrid1.frame = CGRectMake(frame1.origin.x + frame1.size.width + 5,
+ frame1.origin.y,
+ _buttonOptionsGrid1.frame.size.width,
+ _buttonOptionsGrid1.frame.size.height);
+
+ _buttonOptionsGrid2.frame = CGRectMake(frame2.origin.x + frame2.size.width - _buttonOptionsGrid2.frame.size.width,
+ frame2.origin.y - _buttonOptionsGrid2.frame.size.height - 5,
+ _buttonOptionsGrid2.frame.size.width,
+ _buttonOptionsGrid2.frame.size.height);
+
+
+}
+
+- (void)showOptionsFromButton:(UIButton *)button
+{
+ UIViewController *optionsControllerToShow = button == _buttonOptionsGrid1 ? _optionsController1 : _optionsController2;
+
+ if (INTERFACE_IS_PHONE)
+ {
+ [self presentModalViewController:_optionsController1 animated:YES];
+ }
+ else
+ {
+ if(![_popOverController isPopoverVisible])
+ {
+ _popOverController = [[UIPopoverController alloc] initWithContentViewController:optionsControllerToShow];
+ [_popOverController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
+ }
+ else
+ {
+ [self optionsDoneAction];
+ }
+ }
+}
+
+- (void)optionsDoneAction
+{
+ if (INTERFACE_IS_PHONE)
+ {
+ [self dismissModalViewControllerAnimated:YES];
+ }
+ else
+ {
+ [_popOverController dismissPopoverAnimated:YES];
+ _popOverController = nil;
+ }
+}
+
+//////////////////////////////////////////////////////////////
+#pragma mark GMGridViewDataSource
+//////////////////////////////////////////////////////////////
+
+- (NSInteger)numberOfItemsInGMGridView:(GMGridView *)gridView
+{
+ return 50;
+}
+
+- (CGSize)sizeForItemsInGMGridView:(GMGridView *)gridView
+{
+ if (INTERFACE_IS_PHONE)
+ {
+ return CGSizeMake(140, 110);
+ }
+ else
+ {
+ return CGSizeMake(230, 175);
+ }
+}
+
+- (UIView *)GMGridView:(GMGridView *)gridView viewForItemAtIndex:(NSInteger)index
+{
+ CGSize size = [self sizeForItemsInGMGridView:gridView];
+
+ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
+ view.backgroundColor = gridView == _gmGridView1 ? [UIColor purpleColor] : [UIColor greenColor];
+ view.layer.masksToBounds = NO;
+ view.layer.cornerRadius = 8;
+ view.layer.shadowColor = [UIColor grayColor].CGColor;
+ view.layer.shadowOffset = CGSizeMake(5, 5);
+ view.layer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
+ view.layer.shadowRadius = 8;
+
+ UILabel *label = [[UILabel alloc] initWithFrame:view.frame];
+ label.text = [NSString stringWithFormat:@"%d", index];
+ label.textAlignment = UITextAlignmentCenter;
+ label.backgroundColor = [UIColor clearColor];
+ label.textColor = [UIColor blackColor];
+ label.font = [UIFont boldSystemFontOfSize:20];
+ [view addSubview:label];
+
+ return view;
+}
+
+
+//////////////////////////////////////////////////////////////
+#pragma mark GMGridViewSortingDelegate
+//////////////////////////////////////////////////////////////
+
+- (void)GMGridView:(GMGridView *)gridView didStartMovingView:(UIView *)view
+{
+ [UIView animateWithDuration:0.3
+ delay:0
+ options:UIViewAnimationOptionAllowUserInteraction
+ animations:^{
+ view.backgroundColor = [UIColor orangeColor];
+ view.layer.shadowOpacity = 0.7;
+ }
+ completion:nil
+ ];
+}
+
+- (void)GMGridView:(GMGridView *)gridView didEndMovingView:(UIView *)view
+{
+ [UIView animateWithDuration:0.3
+ delay:0
+ options:UIViewAnimationOptionAllowUserInteraction
+ animations:^{
+ view.backgroundColor = (gridView == _gmGridView1) ? [UIColor purpleColor] : [UIColor greenColor];
+ view.layer.shadowOpacity = 0;
+ }
+ completion:nil
+ ];
+}
+
+- (BOOL)GMGridView:(GMGridView *)gridView shouldAllowShakingBehaviorWhenMovingView:(UIView *)view atIndex:(NSInteger)index
+{
+ return YES;
+}
+
+- (void)GMGridView:(GMGridView *)gridView moveItemAtIndex:(NSInteger)oldIndex toIndex:(NSInteger)newIndex
+{
+ // We dont care about this in this demo (see demo 1 for examples)
+}
+
+- (void)GMGridView:(GMGridView *)gridView exchangeItemAtIndex:(NSInteger)index1 withItemAtIndex:(NSInteger)index2
+{
+ // We dont care about this in this demo (see demo 1 for examples)
+}
+
+
+//////////////////////////////////////////////////////////////
+#pragma mark DraggableGridViewTransformingDelegate
+//////////////////////////////////////////////////////////////
+
+- (CGSize)GMGridView:(GMGridView *)gridView sizeInFullSizeForView:(UIView *)view
+{
+ if (INTERFACE_IS_PHONE)
+ {
+ return CGSizeMake(310, 310);
+ }
+ else
+ {
+ return CGSizeMake(700, 530);
+ }
+}
+
+- (UIView *)GMGridView:(GMGridView *)gridView fullSizeViewForView:(UIView *)view
+{
+ UIView *fullView = [[UIView alloc] init];
+ fullView.backgroundColor = [UIColor yellowColor];
+ fullView.layer.masksToBounds = NO;
+ fullView.layer.cornerRadius = 8;
+
+ CGSize size = [self GMGridView:gridView sizeInFullSizeForView:view];
+ fullView.bounds = CGRectMake(0, 0, size.width, size.height);
+
+ UILabel *label = [[UILabel alloc] initWithFrame:fullView.bounds];
+ label.text = @"Fullscreen View";
+ label.textAlignment = UITextAlignmentCenter;
+ label.backgroundColor = [UIColor clearColor];
+ label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+
+ if (INTERFACE_IS_PHONE)
+ {
+ label.font = [UIFont boldSystemFontOfSize:15];
+ }
+ else
+ {
+ label.font = [UIFont boldSystemFontOfSize:20];
+ }
+
+ [fullView addSubview:label];
+
+
+ return fullView;
+}
+
+- (void)GMGridView:(GMGridView *)gridView didStartTransformingView:(UIView *)view
+{
+ [UIView animateWithDuration:0.5
+ delay:0
+ options:UIViewAnimationOptionAllowUserInteraction
+ animations:^{
+ view.backgroundColor = [UIColor blueColor];
+ view.layer.shadowOpacity = 0.7;
+ }
+ completion:nil];
+}
+
+- (void)GMGridView:(GMGridView *)gridView didEndTransformingView:(UIView *)view
+{
+ [UIView animateWithDuration:0.5
+ delay:0
+ options:UIViewAnimationOptionAllowUserInteraction
+ animations:^{
+ view.backgroundColor = (gridView == _gmGridView1) ? [UIColor purpleColor] : [UIColor greenColor];
+ view.layer.shadowOpacity = 0;
+ }
+ completion:nil];
+}
+
+- (void)GMGridView:(GMGridView *)gridView didEnterFullSizeForView:(UIView *)view
+{
+
+}
+
+
+@end
View
5 GMGridView/GMGridView-Prefix.pch
@@ -12,3 +12,8 @@
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
+
+
+#define INTERFACE_IS_PAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
+#define INTERFACE_IS_PHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
+
View
8 README
@@ -4,6 +4,13 @@ GM-GRID-VIEW
An iOS Grid-View allowing the user to sort the views in the scrollView and also to see the views in fullsize by pinching them.
This view is inspired by the UITableView and uses a datasource and delegates in order to get the data and interact with it.
+The best sorting sorting style (swap or push) depens on the frame of the grid; you can choose that one thats suits you best.
+Same applies to the layout strategy (vertical or horizontal).
+
+May working examples provided in the demo app!
+
+---
+
Requirements:
- iOS 5 (to access the UIScrollView gestureRecognizers)
- ARC (Automatic Reference Counting)
@@ -30,7 +37,6 @@ Features - Fullsize:
- Every view doesnt have it's own gesture recognizers, the main view handles a set of gestures for ALL views
COMING SOON :
-- More demo content
- Changing the zoom scale dynamically (when pinching to go fullscreen)
- Delegate callbacks for tap and double-tap

0 comments on commit 74b9347

Please sign in to comment.