Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added another basic animation #90

Open
wants to merge 2 commits into from

1 participant

@depl0y

Added a basic popup animation, which I use in one of my applications.

depl0y added some commits
@depl0y depl0y Popup animation added
Added a basic popup animation, which I use in one of my applications.
ee31dee
@depl0y depl0y Allow code blocks for animations
This addition allows code blocks for the animation of the cells.
6ac2e6b
@depl0y

I also included code to enable code blocks for the animation of the cells that are being added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 18, 2011
  1. @depl0y

    Popup animation added

    depl0y authored
    Added a basic popup animation, which I use in one of my applications.
  2. @depl0y

    Allow code blocks for animations

    depl0y authored
    This addition allows code blocks for the animation of the cells.
This page is out of date. Refresh to see the latest.
View
8 Classes/AQGridView.h
@@ -50,7 +50,9 @@ typedef enum {
AQGridViewItemAnimationLeft,
AQGridViewItemAnimationTop,
AQGridViewItemAnimationBottom,
- AQGridViewItemAnimationNone
+ AQGridViewItemAnimationNone,
+ AQGridViewItemAnimationPop,
+ AQGridViewitemAnimationBlock
} AQGridViewItemAnimation;
typedef enum {
@@ -58,6 +60,8 @@ typedef enum {
AQGridViewLayoutDirectionHorizontal
} AQGridViewLayoutDirection;
+typedef void (^AnimationBlock)(AQGridViewCell*);
+
@protocol AQGridViewDataSource;
@class AQGridView, AQGridViewData, AQGridViewUpdateInfo;
@@ -205,6 +209,8 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;
- (void) endUpdates; // only call insert/delete/reload calls inside an update block.
- (void) insertItemsAtIndices: (NSIndexSet *) indices withAnimation: (AQGridViewItemAnimation) animation;
+- (void) insertItemsAtIndices:(NSIndexSet *)indices withAnimationBlock:(AnimationBlock) animationBlock;
+
- (void) deleteItemsAtIndices: (NSIndexSet *) indices withAnimation: (AQGridViewItemAnimation) animation;
- (void) reloadItemsAtIndices: (NSIndexSet *) indices withAnimation: (AQGridViewItemAnimation) animation;
View
21 Classes/AQGridView.m
@@ -974,7 +974,6 @@ - (void) endUpdateAnimations
self.animatingCells = [info animateCellUpdatesUsingVisibleContentRect: [self gridViewVisibleBounds]];
-
[_gridData release];
_gridData = [[info newGridViewData] retain];
if ( _selectedIndex != NSNotFound )
@@ -1029,6 +1028,26 @@ - (void) _updateItemsAtIndices: (NSIndexSet *) indices updateAction: (AQGridView
[self endUpdateAnimations];
}
+
+
+- (void) _updateItemsAtIndices:(NSIndexSet*) indices updateAction:(AQGridViewUpdateAction) action withAnimationBlock:(AnimationBlock) animationBlock
+{
+ BOOL needsAnimationSetup = ([_updateInfoStack count] <= _animationCount);
+
+ if (needsAnimationSetup)
+ [self setupUpdateAnimations];
+
+ [[_updateInfoStack lastObject] updateItemsAtIndices: indices updateAction: action withAnimationBlock:animationBlock];
+
+ if (needsAnimationSetup)
+ [self endUpdateAnimations];
+}
+
+- (void) insertItemsAtIndices:(NSIndexSet *)indices withAnimationBlock:(AnimationBlock) animationBlock
+{
+ [self _updateItemsAtIndices:indices updateAction:AQGridViewUpdateActionInsert withAnimationBlock:animationBlock];
+}
+
- (void) insertItemsAtIndices: (NSIndexSet *) indices withAnimation: (AQGridViewItemAnimation) animation
{
[self _updateItemsAtIndices: indices updateAction: AQGridViewUpdateActionInsert withAnimation: animation];
View
5 Classes/AQGridViewUpdateInfo.h
@@ -82,6 +82,11 @@
- (void) updateItemsAtIndices: (NSIndexSet *) indices
updateAction: (AQGridViewUpdateAction) action
withAnimation: (AQGridViewItemAnimation) animation;
+
+- (void) updateItemsAtIndices: (NSIndexSet *) indices
+ updateAction: (AQGridViewUpdateAction) action
+ withAnimationBlock: (AnimationBlock) animationBlock;
+
- (void) moveItemAtIndex: (NSUInteger) index
toIndex: (NSUInteger) index
withAnimation: (AQGridViewItemAnimation) animation;
View
53 Classes/AQGridViewUpdateInfo.m
@@ -126,6 +126,24 @@ - (void) updateItemsAtIndices: (NSIndexSet *) indices
}
}
+- (void) updateItemsAtIndices: (NSIndexSet *) indices
+ updateAction: (AQGridViewUpdateAction) action
+ withAnimationBlock: (AnimationBlock) animationBlock
+{
+ NSMutableArray * array = [self updateItemArrayForAction: action];
+ NSUInteger i = [indices firstIndex];
+ while ( i != NSNotFound )
+ {
+ AQGridViewUpdateItem * item = [[AQGridViewUpdateItem alloc] initWithIndex: i
+ action: action
+ animationBlock:animationBlock];
+ [array addObject: item];
+ [item release];
+
+ i = [indices indexGreaterThanIndex: i];
+ }
+}
+
- (void) moveItemAtIndex: (NSUInteger) index
toIndex: (NSUInteger) newIndex
withAnimation: (AQGridViewItemAnimation) animation
@@ -521,6 +539,7 @@ - (UIImageView *) animateDeletionForCell: (AQGridViewCell *) cell withAnimation:
// this is what we'll animate
switch ( animation )
{
+ case AQGridViewItemAnimationPop: // No action needed for the pop animation
case AQGridViewItemAnimationFade:
// nothing else left for the fade animation
break;
@@ -556,6 +575,10 @@ - (UIImageView *) animateDeletionForCell: (AQGridViewCell *) cell withAnimation:
imageView.center = center;
break;
}
+ case AQGridViewitemAnimationBlock:
+ {
+ break;
+ }
default:
break;
@@ -564,6 +587,14 @@ - (UIImageView *) animateDeletionForCell: (AQGridViewCell *) cell withAnimation:
return ( imageView );
}
+- (void) animateInsertionForCell:(AQGridViewCell*) cell withAnimationBlock:(AnimationBlock) animationBlock
+{
+ [_gridView addSubview: cell];
+ [UIView setAnimationsEnabled: YES];
+
+ animationBlock(cell);
+}
+
- (void) animateInsertionForCell: (AQGridViewCell *) cell withAnimation: (AQGridViewItemAnimation) animation
{
[UIView setAnimationsEnabled: NO];
@@ -625,7 +656,21 @@ - (void) animateInsertionForCell: (AQGridViewCell *) cell withAnimation: (AQGrid
[itemsToSetBeforeAnimation setObject: [NSValue valueWithCGPoint: center] forKey: @"center"];
break;
}
+ case AQGridViewItemAnimationPop:
+ {
+ float percentageOfOriginalWidth = 10; // Make this higher or lower to start with a small or bigger picture
+ float width = (cellSize.width / 100) * percentageOfOriginalWidth; // 10 percent of original size
+ float inset = (cellSize.width / 2) - (width / 2);
+ CGRect newSize = CGRectInset(cell.frame, inset, inset);
+ [itemsToAnimate setObject:[NSValue valueWithCGRect:cell.frame] forKey: @"frame"];
+ [itemsToSetBeforeAnimation setObject: [NSValue valueWithCGRect:newSize] forKey: @"frame"];
+ break;
+ }
+ case AQGridViewitemAnimationBlock:
+ {
+ break;
+ }
default:
break;
}
@@ -680,6 +725,7 @@ - (void) animateReloadForCell: (AQGridViewCell *) newCell originalCell: (AQGridV
switch ( animation )
{
case AQGridViewItemAnimationFade:
+ case AQGridViewItemAnimationPop:
default:
break; // fade always happens
@@ -885,7 +931,12 @@ - (NSSet *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
AQGridViewCell * cell = [_gridView createPreparedCellForIndex: item.index usingGridData: _newGridData];
if ( cell != nil )
{
- [self animateInsertionForCell: cell withAnimation: item.animation];
+ if (item.animation == AQGridViewitemAnimationBlock)
+ {
+ [self animateInsertionForCell:cell withAnimationBlock:item.animationBlock];
+ }
+ else
+ [self animateInsertionForCell: cell withAnimation: item.animation];
[_gridView delegateWillDisplayCell: cell atIndex: item.index];
[newVisibleCells addObject: [AQGridViewAnimatorItem itemWithView: cell index: item.index]];
}
View
3  Classes/AQGridViewUpdateItem.h
@@ -50,10 +50,12 @@ typedef enum {
NSUInteger _newIndex;
AQGridViewUpdateAction _action;
AQGridViewItemAnimation _animation;
+ AnimationBlock _animationBlock;
NSInteger _offset;
}
- (id) initWithIndex: (NSUInteger) index action: (AQGridViewUpdateAction) action animation: (AQGridViewItemAnimation) animation;
+- (id) initWithIndex:(NSUInteger)index action:(AQGridViewUpdateAction)action animationBlock:(AnimationBlock)animationBlock;
- (NSComparisonResult) compare: (AQGridViewUpdateItem *) other;
- (NSComparisonResult) inverseCompare: (AQGridViewUpdateItem *) other;
@@ -62,6 +64,7 @@ typedef enum {
@property (nonatomic) NSUInteger newIndex; // only valid for AQGridViewUpdateActionMove
@property (nonatomic, readonly) AQGridViewUpdateAction action;
@property (nonatomic, readonly) AQGridViewItemAnimation animation;
+@property (nonatomic, readonly) AnimationBlock animationBlock;
// this is an offset to apply to the index, due to other changes in the list which occurred since this index was chosen
@property (nonatomic) NSInteger offset;
View
16 Classes/AQGridViewUpdateItem.m
@@ -38,7 +38,7 @@
@implementation AQGridViewUpdateItem
-@synthesize originalIndex=_index, newIndex=_newIndex, action=_action, animation=_animation, offset=_offset;
+@synthesize originalIndex=_index, newIndex=_newIndex, action=_action, animation=_animation, offset=_offset, animationBlock = _animationBlock;
- (id) initWithIndex: (NSUInteger) index action: (AQGridViewUpdateAction) action animation: (AQGridViewItemAnimation) animation
{
@@ -53,6 +53,20 @@ - (id) initWithIndex: (NSUInteger) index action: (AQGridViewUpdateAction) action
return ( self );
}
+- (id) initWithIndex:(NSUInteger)index action:(AQGridViewUpdateAction)action animationBlock:(AnimationBlock)animationBlock
+{
+ self = [super init];
+ if ( self == nil )
+ return ( nil );
+
+ _index = index;
+ _action = action;
+ _animation = AQGridViewitemAnimationBlock;
+ _animationBlock = animationBlock;
+
+ return ( self );
+}
+
- (void) setNewIndex: (NSUInteger) value
{
NSAssert(self.action == AQGridViewUpdateActionMove, @"newIndex set on a non-move update item");
Something went wrong with that request. Please try again.