From 1c29777c0f12933e536f99b60c9fe9f7dbeedf71 Mon Sep 17 00:00:00 2001 From: Mike Enriquez Date: Thu, 26 Jan 2012 14:41:41 -0500 Subject: [PATCH] Improve performance of shadow while rotating --- .../FirstTopViewController.m | 27 ++++++++++- .../ECSlidingViewController.h | 3 ++ .../ECSlidingViewController.m | 45 ++++++++++--------- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/ECSlidingViewController/FirstTopViewController.m b/ECSlidingViewController/FirstTopViewController.m index 734928f..73a61a0 100644 --- a/ECSlidingViewController/FirstTopViewController.m +++ b/ECSlidingViewController/FirstTopViewController.m @@ -32,9 +32,32 @@ { // if going from portrait to landscape or landscape to portrait if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation) != UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { - CGRect bounds = self.view.layer.bounds; - self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(bounds.origin.y, bounds.origin.x, bounds.size.height, bounds.size.width)].CGPath; + // adjust peek amount + if ([self.slidingViewController underLeftShowing] && UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { + [self.slidingViewController jumpToPeekAmount:26.0f inDirection:ECSlideRight]; + } else if ([self.slidingViewController underLeftShowing] && UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { + [self.slidingViewController jumpToPeekAmount:60.0f inDirection:ECSlideRight]; + } else if ([self.slidingViewController underRightShowing] && UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { + [self.slidingViewController jumpToPeekAmount:26.0f inDirection:ECSlideLeft]; + } else if ([self.slidingViewController underRightShowing] && UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { + [self.slidingViewController jumpToPeekAmount:60.0f inDirection:ECSlideLeft]; + } } + + self.view.layer.shadowPath = nil; + self.view.layer.shouldRasterize = YES; +} + +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation +{ + if ([self.slidingViewController underLeftShowing]) { + [self.slidingViewController jumpToPeekAmount:40.0f inDirection:ECSlideRight]; + } else if ([self.slidingViewController underRightShowing]) { + [self.slidingViewController jumpToPeekAmount:40.0f inDirection:ECSlideLeft]; + } + + self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath; + self.view.layer.shouldRasterize = NO; } - (IBAction)revealMenu:(id)sender diff --git a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h index 9906fa0..f8e7060 100644 --- a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h +++ b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h @@ -22,7 +22,10 @@ typedef enum { - (void)slideInDirection:(ECSlideDirection)slideDirection peekAmount:(CGFloat)peekAmount onComplete:(void(^)())completeBlock; - (void)enablePanningInDirection:(ECSlideDirection)slideDirection forView:(UIView *)view peekAmount:(CGFloat)peekAmount; +- (void)jumpToPeekAmount:(CGFloat)peekAmount inDirection:(ECSlideDirection)direction; - (void)reset; +- (BOOL)underLeftShowing; +- (BOOL)underRightShowing; @end diff --git a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m index 88b457f..0d408cf 100644 --- a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m +++ b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m @@ -29,8 +29,6 @@ - (CGFloat)resettedCenter; - (CGFloat)screenWidth; - (CGFloat)screenWidthForOrientation:(UIInterfaceOrientation)orientation; -- (BOOL)underLeftShowing; -- (BOOL)underRightShowing; - (void)underLeftWillAppear; - (void)underRightWillAppear; - (void)topDidReset; @@ -166,16 +164,8 @@ - (void)slideInDirection:(ECSlideDirection)slideDirection peekAmount:(CGFloat)peekAmount onComplete:(void(^)())completeBlock; { - CGFloat newCenter = self.topView.center.x; - - if (slideDirection == ECSlideLeft) { - newCenter = -self.screenWidth + self.resettedCenter + peekAmount; - } else if (slideDirection == ECSlideRight) { - newCenter = self.screenWidth + self.resettedCenter - peekAmount; - } - [UIView animateWithDuration:0.25f animations:^{ - [self updateTopViewHorizontalCenter:newCenter]; + [self jumpToPeekAmount:peekAmount inDirection:slideDirection]; } completion:^(BOOL finished) { if (completeBlock) { completeBlock(); @@ -196,6 +186,19 @@ } } +- (void)jumpToPeekAmount:(CGFloat)peekAmount inDirection:(ECSlideDirection)slideDirection +{ + CGFloat newCenter = self.topView.center.x; + + if (slideDirection == ECSlideLeft) { + newCenter = -self.screenWidth + self.resettedCenter + peekAmount; + } else if (slideDirection == ECSlideRight) { + newCenter = self.screenWidth + self.resettedCenter - peekAmount; + } + + [self updateTopViewHorizontalCenter:newCenter]; +} + - (void)reset { [UIView animateWithDuration:0.25f animations:^{ @@ -203,6 +206,16 @@ }]; } +- (BOOL)underLeftShowing +{ + return self.topView.frame.origin.x > 0; +} + +- (BOOL)underRightShowing +{ + return self.topView.frame.origin.x < 0; +} + - (NSUInteger)autoResizeToFillScreen { return (UIViewAutoresizingFlexibleWidth | @@ -287,16 +300,6 @@ return size.width; } -- (BOOL)underLeftShowing -{ - return self.topView.frame.origin.x > 0; -} - -- (BOOL)underRightShowing -{ - return self.topView.frame.origin.x < 0; -} - - (void)underLeftWillAppear { [self addTopViewSnapshot];