Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds a fade animation on rotation (as Springboard does)

  • Loading branch information...
commit fd1887601c2fb1f3707fa56cba2a02cce33dc949 1 parent 5338da7
@steipete steipete authored committed
Showing with 35 additions and 4 deletions.
  1. +35 −4 GMGridView/API/GMGridView.m
View
39 GMGridView/API/GMGridView.m
@@ -75,6 +75,7 @@ @interface GMGridView () <UIGestureRecognizerDelegate, UIScrollViewDelegate>
CGFloat _lastRotation;
CGFloat _lastScale;
BOOL _inFullSizeMode;
+ BOOL _rotationActive;
}
@property (nonatomic, readonly) BOOL itemsSubviewsCacheIsValid;
@@ -119,6 +120,9 @@ - (void)queueReusableCell:(GMGridViewCell *)cell;
// Memory warning
- (void)receivedMemoryWarningNotification:(NSNotification *)notification;
+// Rotation handling
+- (void)willRotate:(NSNotification *)notification;
+
@end
@@ -243,6 +247,7 @@ - (id)initWithFrame:(CGRect)frame
_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;
}
@@ -251,6 +256,7 @@ - (id)initWithFrame:(CGRect)frame
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
}
//////////////////////////////////////////////////////////////
@@ -261,12 +267,33 @@ - (void)layoutSubviews
{
[super layoutSubviews];
- [self recomputeSize];
- [self relayoutItemsAnimated:NO];
- [self loadRequiredItems];
+ void (^layoutBlock)(void) = ^{
+ [self recomputeSize];
+ [self relayoutItemsAnimated:NO];
+ [self loadRequiredItems];
+ };
+
+ if (_rotationActive) {
+ CATransition *transition = [CATransition animation];
+ transition.duration = 0.25f;
+ transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.type = kCATransitionFade;
+ [_scrollView.layer addAnimation:transition forKey:@"rotationAnimation"];
+ _rotationActive = NO;
+
+ [UIView animateWithDuration:0
+ delay:0
+ options:UIViewAnimationOptionOverrideInheritedDuration
+ animations:^{
+ layoutBlock();
+ }
+ completion:nil
+ ];
+ }else {
+ layoutBlock();
+ }
}
-
//////////////////////////////////////////////////////////////
#pragma mark Setters / getters
//////////////////////////////////////////////////////////////
@@ -1267,6 +1294,10 @@ - (void)receivedMemoryWarningNotification:(NSNotification *)notification
[_reusableCells removeAllObjects];
}
+- (void)willRotate:(NSNotification *)notification
+{
+ _rotationActive = YES;
+}
//////////////////////////////////////////////////////////////
#pragma mark public methods
Please sign in to comment.
Something went wrong with that request. Please try again.