Improve performance of shadow while rotating

This commit is contained in:
Mike Enriquez
2012-01-26 14:41:41 -05:00
parent b12363e995
commit 1c29777c0f
3 changed files with 52 additions and 23 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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];