- Added scale animation
This commit is contained in:
parent
7fa9e10b3e
commit
373be13080
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return 15;
|
||||
return 10;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
|
|
@ -40,8 +40,28 @@
|
|||
cell.textLabel.text = @"Sign Out";
|
||||
break;
|
||||
|
||||
default:
|
||||
cell.textLabel.text = @"Random Cell";
|
||||
case 4:
|
||||
cell.textLabel.text = @"No Animation";
|
||||
break;
|
||||
|
||||
case 5:
|
||||
cell.textLabel.text = @"Slide Animation";
|
||||
break;
|
||||
|
||||
case 6:
|
||||
cell.textLabel.text = @"Fade Animation";
|
||||
break;
|
||||
|
||||
case 7:
|
||||
cell.textLabel.text = @"Slide And Fade Animation";
|
||||
break;
|
||||
|
||||
case 8:
|
||||
cell.textLabel.text = @"Scale Animation";
|
||||
break;
|
||||
|
||||
case 9:
|
||||
cell.textLabel.text = @"Scale And Fade Animation";
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +74,7 @@
|
|||
bundle: nil];
|
||||
|
||||
UIViewController *vc ;
|
||||
MenuRevealAnimation revealAnimation = MenuRevealAnimationNone;
|
||||
|
||||
switch (indexPath.row)
|
||||
{
|
||||
|
|
@ -74,11 +95,40 @@
|
|||
return;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
revealAnimation = MenuRevealAnimationNone;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
revealAnimation = MenuRevealAnimationSlide;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
revealAnimation = MenuRevealAnimationFade;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
revealAnimation = MenuRevealAnimationSlideAndFade;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
revealAnimation = MenuRevealAnimationScale;
|
||||
break;
|
||||
|
||||
case 9:
|
||||
revealAnimation = MenuRevealAnimationScaleAndFade;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
[[SlideNavigationController sharedInstance] switchToViewController:vc withCompletion:nil];
|
||||
if (vc)
|
||||
[[SlideNavigationController sharedInstance] switchToViewController:vc withCompletion:nil];
|
||||
else
|
||||
[[SlideNavigationController sharedInstance] closeMenuWithCompletion:^{
|
||||
[SlideNavigationController sharedInstance].menuRevealAnimation = revealAnimation;
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@ typedef enum{
|
|||
MenuRevealAnimationNone,
|
||||
MenuRevealAnimationFade,
|
||||
MenuRevealAnimationSlide,
|
||||
MenuRevealAnimationSlideAndFade
|
||||
MenuRevealAnimationSlideAndFade,
|
||||
MenuRevealAnimationScale,
|
||||
MenuRevealAnimationScaleAndFade
|
||||
}MenuRevealAnimation;
|
||||
|
||||
@interface SlideNavigationController : UINavigationController <UINavigationControllerDelegate>
|
||||
|
|
@ -60,6 +62,7 @@ typedef enum{
|
|||
@property (nonatomic, assign) CGFloat menuRevealAnimationFadeMaximumAlpha;
|
||||
@property (nonatomic, strong) UIColor *menuRevealAnimationFadeColor;
|
||||
@property (nonatomic, assign) CGFloat menuRevealAnimationSlideMovement;
|
||||
@property (nonatomic, assign) CGFloat menuRevealAnimationScaleMinScale;
|
||||
|
||||
+ (SlideNavigationController *)sharedInstance;
|
||||
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
#define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200
|
||||
#define MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT 100
|
||||
#define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .8
|
||||
#define MENU_REVEAL_ANIMATION_DEFAULT_SCALE_MINIMUM_SCALE .85
|
||||
#define STATUS_BAR_HEIGHT 20
|
||||
|
||||
static SlideNavigationController *singletonInstance;
|
||||
|
|
@ -90,6 +91,7 @@ static SlideNavigationController *singletonInstance;
|
|||
- (void)setup
|
||||
{
|
||||
self.menuRevealAnimationSlideMovement = MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT;
|
||||
self.menuRevealAnimationScaleMinScale = MENU_REVEAL_ANIMATION_DEFAULT_SCALE_MINIMUM_SCALE;
|
||||
self.menuRevealAnimationFadeMaximumAlpha = MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA;
|
||||
self.menuRevealAnimation = MenuRevealAnimationSlideAndFade;
|
||||
self.landscapeSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
|
||||
|
|
@ -106,6 +108,7 @@ static SlideNavigationController *singletonInstance;
|
|||
self.view.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
||||
|
||||
[self setEnableSwipeGesture:YES];
|
||||
[self updateMenuFrameAndTransformAccordingToOrientation];
|
||||
}
|
||||
|
||||
- (void)viewWillLayoutSubviews
|
||||
|
|
@ -120,9 +123,6 @@ static SlideNavigationController *singletonInstance;
|
|||
{
|
||||
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
|
||||
|
||||
// Update rotation animation
|
||||
[self updateMenuFrameAndTransformAccordingToOrientation];
|
||||
|
||||
// Avoid an ugnly shadow in background while rotating
|
||||
self.view.layer.shadowOpacity = 0;
|
||||
}
|
||||
|
|
@ -131,6 +131,9 @@ static SlideNavigationController *singletonInstance;
|
|||
{
|
||||
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
|
||||
|
||||
// Update rotation animation
|
||||
[self updateMenuFrameAndTransformAccordingToOrientation];
|
||||
|
||||
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
|
||||
|
||||
// we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back
|
||||
|
|
@ -139,17 +142,13 @@ static SlideNavigationController *singletonInstance;
|
|||
|
||||
- (void)updateMenuFrameAndTransformAccordingToOrientation
|
||||
{
|
||||
// Animate rotatation when menu is open and device rotates
|
||||
CGAffineTransform transform = self.view.transform;
|
||||
self.leftMenu.view.transform = transform;
|
||||
self.rightMenu.view.transform = transform;
|
||||
|
||||
CGRect rect = self.view.frame;
|
||||
self.leftMenu.view.frame = rect;
|
||||
self.rightMenu.view.frame = rect;
|
||||
|
||||
// Move menus accordingly to avoid a weird animation during opening/closing menu after a rotation
|
||||
[self updateMenuAnimation:MenuLeft];
|
||||
[self updateMenuAnimation:MenuRight];
|
||||
self.leftMenu.view.frame = [self initialRectForMenu];
|
||||
self.rightMenu.view.frame = [self initialRectForMenu];
|
||||
}
|
||||
|
||||
#pragma mark - Public Methods -
|
||||
|
|
@ -386,14 +385,17 @@ static SlideNavigationController *singletonInstance;
|
|||
? (self.horizontalLocation / self.maxXForDragging)
|
||||
: (self.horizontalLocation / self.minXForDragging);
|
||||
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationFade ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationSlideAndFade ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
|
||||
{
|
||||
self.menuRevealFadeAnimationView.frame = menuViewController.view.bounds;
|
||||
[menuViewController.view addSubview:self.menuRevealFadeAnimationView];
|
||||
self.menuRevealFadeAnimationView.alpha = self.menuRevealAnimationFadeMaximumAlpha - (self.menuRevealAnimationFadeMaximumAlpha *progress);
|
||||
}
|
||||
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationSlide || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationSlide ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
|
||||
{
|
||||
NSInteger location = (menu == MenuLeft)
|
||||
? (self.menuRevealAnimationSlideMovement * -1) + (self.menuRevealAnimationSlideMovement * progress)
|
||||
|
|
@ -405,34 +407,56 @@ static SlideNavigationController *singletonInstance;
|
|||
if (menu == MenuRight)
|
||||
location = (location < 0) ? 0 : location;
|
||||
|
||||
CGRect rect = menuViewController.view.frame;
|
||||
BOOL isIos7 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0");
|
||||
CGRect rect = [self initialRectForMenu];
|
||||
|
||||
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
|
||||
{
|
||||
rect.origin.y = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? location : location*-1;
|
||||
|
||||
if (!isIos7)
|
||||
{
|
||||
// For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
|
||||
rect.origin.x = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? 0 : STATUS_BAR_HEIGHT;
|
||||
rect.size.width = self.view.frame.size.width-STATUS_BAR_HEIGHT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.origin.x = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? location : location*-1;
|
||||
|
||||
if (!isIos7)
|
||||
{
|
||||
// For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
|
||||
rect.origin.y = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? STATUS_BAR_HEIGHT : 0;
|
||||
rect.size.height = self.view.frame.size.height-STATUS_BAR_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
menuViewController.view.frame = rect;
|
||||
}
|
||||
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationScale ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
|
||||
{
|
||||
CGFloat scale = MIN(1, (1-self.menuRevealAnimationScaleMinScale) *progress + self.menuRevealAnimationScaleMinScale);
|
||||
menuViewController.view.transform = CGAffineTransformScale(self.view.transform, scale, scale);
|
||||
}
|
||||
}
|
||||
|
||||
- (CGRect)initialRectForMenu
|
||||
{
|
||||
CGRect rect = self.view.frame;
|
||||
rect.origin.x = 0;
|
||||
rect.origin.y = 0;
|
||||
|
||||
BOOL isIos7 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0");
|
||||
|
||||
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
|
||||
{
|
||||
if (!isIos7)
|
||||
{
|
||||
// For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
|
||||
rect.origin.x = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? 0 : STATUS_BAR_HEIGHT;
|
||||
rect.size.width = self.view.frame.size.width-STATUS_BAR_HEIGHT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isIos7)
|
||||
{
|
||||
// For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
|
||||
rect.origin.y = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? STATUS_BAR_HEIGHT : 0;
|
||||
rect.size.height = self.view.frame.size.height-STATUS_BAR_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
- (void)prepareMenuForReveal:(Menu)menu forcePrepare:(BOOL)forcePrepare
|
||||
|
|
@ -444,19 +468,22 @@ static SlideNavigationController *singletonInstance;
|
|||
UIViewController *menuViewController = (menu == MenuLeft) ? self.leftMenu : self.rightMenu;
|
||||
UIViewController *removingMenuViewController = (menu == MenuLeft) ? self.rightMenu : self.leftMenu;
|
||||
|
||||
[self updateMenuFrameAndTransformAccordingToOrientation];
|
||||
//[self updateMenuFrameAndTransformAccordingToOrientation];
|
||||
|
||||
// If already has been added to the view (has superview) it means it has been initialized so avoid reinitializing
|
||||
if (menuViewController.view.superview)
|
||||
return;
|
||||
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationFade ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationSlideAndFade ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
|
||||
{
|
||||
self.menuRevealFadeAnimationView.alpha = self.menuRevealAnimationFadeMaximumAlpha;
|
||||
self.menuRevealFadeAnimationView.frame = menuViewController.view.bounds;
|
||||
}
|
||||
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationSlide || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationSlide ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
|
||||
{
|
||||
CGRect rect = menuViewController.view.frame;
|
||||
|
||||
|
|
@ -486,6 +513,12 @@ static SlideNavigationController *singletonInstance;
|
|||
menuViewController.view.frame = rect;
|
||||
}
|
||||
|
||||
if (self.menuRevealAnimation == MenuRevealAnimationScale ||
|
||||
self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
|
||||
{
|
||||
menuViewController.view.transform = CGAffineTransformScale(self.view.transform, self.menuRevealAnimationScaleMinScale, self.menuRevealAnimationScaleMinScale);
|
||||
}
|
||||
|
||||
[removingMenuViewController.view removeFromSuperview];
|
||||
[self.view.window insertSubview:menuViewController.view atIndex:0];
|
||||
}
|
||||
|
|
@ -581,7 +614,9 @@ static SlideNavigationController *singletonInstance;
|
|||
|
||||
if (aPanRecognizer.state == UIGestureRecognizerStateBegan)
|
||||
{
|
||||
[self prepareMenuForReveal:menu forcePrepare:YES];
|
||||
if (![self isMenuOpen])
|
||||
[self prepareMenuForReveal:menu forcePrepare:YES];
|
||||
|
||||
self.draggingPoint = translation;
|
||||
lastMenu = menu;
|
||||
}
|
||||
|
|
@ -728,4 +763,11 @@ static SlideNavigationController *singletonInstance;
|
|||
self.menuRevealFadeAnimationView.backgroundColor = menuRevealAnimationFadeColor;
|
||||
}
|
||||
|
||||
- (void)setMenuRevealAnimation:(MenuRevealAnimation)menuRevealAnimation
|
||||
{
|
||||
_menuRevealAnimation = menuRevealAnimation;
|
||||
|
||||
[self updateMenuFrameAndTransformAccordingToOrientation];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="T7T-Ke-Ksy">
|
||||
<rect key="frame" x="0.0" y="20" width="320" height="548"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<prototypes>
|
||||
|
|
|
|||
Loading…
Reference in New Issue