Permalink
Browse files

Added support for Interface builder / storyboard

  • Loading branch information...
1 parent a1b7231 commit a23c8f911fcc957cd243f31e8228e539cc5e707d @gmoledina committed Jan 8, 2012
Showing with 106 additions and 91 deletions.
  1. +8 −8 GMGridView/GMGridView.h
  2. +98 −83 GMGridView/GMGridView.m
View
@@ -64,20 +64,20 @@ typedef enum
@interface GMGridView : UIView
// Delegates
-@property (nonatomic, gm_weak) NSObject<GMGridViewDataSource> *dataSource; // Required
-@property (nonatomic, gm_weak) NSObject<GMGridViewActionDelegate> *actionDelegate; // Optional - to get taps callback & deleting item
-@property (nonatomic, gm_weak) NSObject<GMGridViewSortingDelegate> *sortingDelegate; // Optional - to enable sorting
-@property (nonatomic, gm_weak) NSObject<GMGridViewTransformationDelegate> *transformDelegate; // Optional - to enable fullsize mode
+@property (nonatomic, gm_weak) IBOutlet NSObject<GMGridViewDataSource> *dataSource; // Required
+@property (nonatomic, gm_weak) IBOutlet NSObject<GMGridViewActionDelegate> *actionDelegate; // Optional - to get taps callback & deleting item
+@property (nonatomic, gm_weak) IBOutlet NSObject<GMGridViewSortingDelegate> *sortingDelegate; // Optional - to enable sorting
+@property (nonatomic, gm_weak) IBOutlet NSObject<GMGridViewTransformationDelegate> *transformDelegate; // Optional - to enable fullsize mode
// Layout Strategy
-@property (nonatomic, strong) id<GMGridViewLayoutStrategy> layoutStrategy; // Default is GMGridViewLayoutVerticalStrategy
+@property (nonatomic, strong) IBOutlet id<GMGridViewLayoutStrategy> layoutStrategy; // Default is GMGridViewLayoutVerticalStrategy
// Editing Mode
@property (nonatomic, getter=isEditing) BOOL editing; // Default is NO - When set to YES, all gestures are disabled and delete buttons shows up on cells
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
// Customizing Options
-@property (nonatomic, gm_weak) UIView *mainSuperView; // Default is self
+@property (nonatomic, gm_weak) IBOutlet UIView *mainSuperView; // Default is self
@property (nonatomic) GMGridViewStyle style; // Default is GMGridViewStyleSwap
@property (nonatomic) NSInteger itemSpacing; // Default is 10
@property (nonatomic) BOOL centerGrid; // Default is YES
@@ -86,8 +86,8 @@ typedef enum
@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; // Messing with the scrollView can lead to unexpected behavior. Avoid changing any
+ // properties or changing its delegate. You have been warned.
// Reusable cells
- (GMGridViewCell *)dequeueReusableCell; // Should be called in GMGridView:cellForItemAtIndex: to reuse a cell
View
@@ -85,6 +85,7 @@ @interface GMGridView () <UIGestureRecognizerDelegate, UIScrollViewDelegate>
@property (atomic) NSInteger firstPositionLoaded;
@property (atomic) NSInteger lastPositionLoaded;
+- (void)commonInit;
// Gestures
- (void)sortingPanGestureUpdated:(UIPanGestureRecognizer *)panGesture;
@@ -166,95 +167,109 @@ - (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
- _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];
-
- /////////////////////////////
- // Transformation gestures :
- _pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureUpdated:)];
- _pinchGesture.delegate = self;
- [self addGestureRecognizer:_pinchGesture];
-
- _rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureUpdated:)];
- _rotationGesture.delegate = self;
- [self addGestureRecognizer:_rotationGesture];
-
- _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureUpdated:)];
- _panGesture.delegate = self;
- [_panGesture setMaximumNumberOfTouches:2];
- [_panGesture setMinimumNumberOfTouches:2];
- [self addGestureRecognizer:_panGesture];
-
- //////////////////////
- // Sorting gestures :
-
- _sortingPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(sortingPanGestureUpdated:)];
- _sortingPanGesture.delegate = self;
- [_scrollView addGestureRecognizer:_sortingPanGesture];
-
- _sortingLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(sortingLongPressGestureUpdated:)];
- _sortingLongPressGesture.numberOfTouchesRequired = 1;
- _sortingLongPressGesture.delegate = self;
- [_scrollView addGestureRecognizer:_sortingLongPressGesture];
-
- ////////////////////////
- // Gesture dependencies
- UIPanGestureRecognizer *panGestureRecognizer = nil;
- if ([_scrollView respondsToSelector:@selector(panGestureRecognizer)]) // iOS5 only
+ [self commonInit];
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder *)aDecoder
+{
+ if ((self = [super initWithCoder:aDecoder]))
+ {
+ [self commonInit];
+ }
+
+ return self;
+}
+
+- (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];
+
+ /////////////////////////////
+ // Transformation gestures :
+ _pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureUpdated:)];
+ _pinchGesture.delegate = self;
+ [self addGestureRecognizer:_pinchGesture];
+
+ _rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureUpdated:)];
+ _rotationGesture.delegate = self;
+ [self addGestureRecognizer:_rotationGesture];
+
+ _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureUpdated:)];
+ _panGesture.delegate = self;
+ [_panGesture setMaximumNumberOfTouches:2];
+ [_panGesture setMinimumNumberOfTouches:2];
+ [self addGestureRecognizer:_panGesture];
+
+ //////////////////////
+ // Sorting gestures :
+
+ _sortingPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(sortingPanGestureUpdated:)];
+ _sortingPanGesture.delegate = self;
+ [_scrollView addGestureRecognizer:_sortingPanGesture];
+
+ _sortingLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(sortingLongPressGestureUpdated:)];
+ _sortingLongPressGesture.numberOfTouchesRequired = 1;
+ _sortingLongPressGesture.delegate = self;
+ [_scrollView addGestureRecognizer:_sortingLongPressGesture];
+
+ ////////////////////////
+ // Gesture dependencies
+ UIPanGestureRecognizer *panGestureRecognizer = nil;
+ if ([_scrollView respondsToSelector:@selector(panGestureRecognizer)]) // iOS5 only
+ {
+ panGestureRecognizer = _scrollView.panGestureRecognizer;
+ }
+ else
+ {
+ for (UIGestureRecognizer *gestureRecognizer in _scrollView.gestureRecognizers)
{
- panGestureRecognizer = _scrollView.panGestureRecognizer;
- }
- else
- {
- for (UIGestureRecognizer *gestureRecognizer in _scrollView.gestureRecognizers)
- {
- if ([gestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")])
- {
- panGestureRecognizer = (UIPanGestureRecognizer *) gestureRecognizer;
- }
+ if ([gestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")])
+ {
+ panGestureRecognizer = (UIPanGestureRecognizer *) gestureRecognizer;
}
}
- [panGestureRecognizer setMaximumNumberOfTouches:1];
- [panGestureRecognizer requireGestureRecognizerToFail:_sortingPanGesture];
-
- self.layoutStrategy = [GMGridViewLayoutStrategyFactory strategyFromType:GMGridViewLayoutVertical];
-
- self.mainSuperView = self;
- self.editing = NO;
- self.itemSpacing = 10;
- self.style = GMGridViewStyleSwap;
- self.minimumPressDuration = 0.2;
- self.showFullSizeViewWithAlphaWhenTransforming = YES;
- self.minEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
- self.clipsToBounds = NO;
-
- _sortFuturePosition = GMGV_INVALID_POSITION;
- _itemSize = CGSizeZero;
-
- _lastScale = 1.0;
- _lastRotation = 0.0;
-
- _minPossibleContentOffset = CGPointMake(0, 0);
- _maxPossibleContentOffset = CGPointMake(0, 0);
-
- _reusableCells = [[NSMutableSet alloc] init];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedMemoryWarningNotification:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotate:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
}
- return self;
+ [panGestureRecognizer setMaximumNumberOfTouches:1];
+ [panGestureRecognizer requireGestureRecognizerToFail:_sortingPanGesture];
+
+ self.layoutStrategy = [GMGridViewLayoutStrategyFactory strategyFromType:GMGridViewLayoutVertical];
+
+ self.mainSuperView = self;
+ self.editing = NO;
+ self.itemSpacing = 10;
+ self.style = GMGridViewStyleSwap;
+ self.minimumPressDuration = 0.2;
+ self.showFullSizeViewWithAlphaWhenTransforming = YES;
+ self.minEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
+ self.clipsToBounds = NO;
+
+ _sortFuturePosition = GMGV_INVALID_POSITION;
+ _itemSize = CGSizeZero;
+
+ _lastScale = 1.0;
+ _lastRotation = 0.0;
+
+ _minPossibleContentOffset = CGPointMake(0, 0);
+ _maxPossibleContentOffset = CGPointMake(0, 0);
+
+ _reusableCells = [[NSMutableSet alloc] init];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedMemoryWarningNotification:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotate:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
}
-
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];

0 comments on commit a23c8f9

Please sign in to comment.