mirror of
https://github.com/zhigang1992/ECSlidingViewController.git
synced 2026-03-27 22:49:37 +08:00
Merge branch 'snapshot_performance'
This commit is contained in:
@@ -28,7 +28,10 @@ typedef enum {
|
||||
} ECResetStrategy;
|
||||
|
||||
/** ECSlidingViewController is a view controller container that presents its child view controllers in two layers. The top layer can be panned to reveal the layers below it. */
|
||||
@interface ECSlidingViewController : UIViewController
|
||||
@interface ECSlidingViewController : UIViewController{
|
||||
CGPoint startTouchPosition;
|
||||
BOOL topViewHasFocus;
|
||||
}
|
||||
|
||||
/** Returns the view controller that will be visible when the top view is slide to the right.
|
||||
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
// Copyright (c) 2012 EdgeCase. All rights reserved.
|
||||
//
|
||||
|
||||
#define HORIZ_SWIPE_DRAG_MIN 5
|
||||
#import "ECSlidingViewController.h"
|
||||
|
||||
@interface ECSlidingViewController()
|
||||
|
||||
@property (nonatomic, strong) UIButton *topViewSnapshot;
|
||||
@property (nonatomic, strong) UIView *topViewSnapshot;
|
||||
@property (nonatomic, unsafe_unretained) CGFloat initialTouchPositionX;
|
||||
@property (nonatomic, unsafe_unretained) CGFloat initialHoizontalCenter;
|
||||
@property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
|
||||
@@ -138,6 +139,9 @@
|
||||
|
||||
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
|
||||
{
|
||||
if(!topViewHasFocus){
|
||||
[self removeTopViewSnapshot];
|
||||
}
|
||||
if ([self underRightShowing] && ![self topViewIsOffScreen]) {
|
||||
[self updateTopViewHorizontalCenter:self.anchorLeftTopViewCenter];
|
||||
} else if ([self underRightShowing] && [self topViewIsOffScreen]) {
|
||||
@@ -149,6 +153,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
|
||||
if(!topViewHasFocus){
|
||||
[self addTopViewSnapshot];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateTopViewHorizontalCenterWithRecognizer:(UIPanGestureRecognizer *)recognizer
|
||||
{
|
||||
CGPoint currentTouchPoint = [recognizer locationInView:self.view];
|
||||
@@ -210,10 +220,11 @@
|
||||
} else {
|
||||
self.panGesture.enabled = NO;
|
||||
}
|
||||
|
||||
if (complete) {
|
||||
complete();
|
||||
}
|
||||
topViewHasFocus = NO;
|
||||
[self addTopViewSnapshot];
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -238,6 +249,8 @@
|
||||
if (complete) {
|
||||
complete();
|
||||
}
|
||||
topViewHasFocus = NO;
|
||||
[self addTopViewSnapshot];
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -246,6 +259,7 @@
|
||||
[UIView animateWithDuration:0.25f animations:^{
|
||||
[self updateTopViewHorizontalCenter:self.resettedCenter];
|
||||
} completion:^(BOOL finished) {
|
||||
topViewHasFocus = YES;
|
||||
[self topViewHorizontalCenterDidChange:self.resettedCenter];
|
||||
}];
|
||||
}
|
||||
@@ -318,9 +332,10 @@
|
||||
- (void)addTopViewSnapshot
|
||||
{
|
||||
if (!self.topViewSnapshot.superview && !self.shouldAllowUserInteractionsWhenAnchored) {
|
||||
self.topViewSnapshot = [[UIButton alloc] initWithFrame:self.topView.bounds];
|
||||
[self.topViewSnapshot setImage:[UIImage imageWithUIView:self.topView] forState:(UIControlStateNormal | UIControlStateHighlighted | UIControlStateSelected)];
|
||||
self.topViewSnapshot = [[UIView alloc] initWithFrame:self.topView.bounds];
|
||||
topViewSnapshot.layer.contents = (id)[UIImage imageWithUIView:self.topView].CGImage;
|
||||
[self.topView addSubview:self.topViewSnapshot];
|
||||
[self.topViewSnapshot addGestureRecognizer:self.resetTapGesture];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,6 +343,7 @@
|
||||
{
|
||||
if (self.topViewSnapshot.superview) {
|
||||
[self.topViewSnapshot removeFromSuperview];
|
||||
topViewSnapshot = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,10 +396,7 @@
|
||||
|
||||
- (void)underLeftWillAppear
|
||||
{
|
||||
[self addTopViewSnapshot];
|
||||
if (resetStrategy & ECTapping) {
|
||||
[self.topView addGestureRecognizer:self.resetTapGesture];
|
||||
}
|
||||
topViewHasFocus = NO;
|
||||
self.underRightView.hidden = YES;
|
||||
[self.underLeftViewController viewWillAppear:NO];
|
||||
self.underLeftView.hidden = NO;
|
||||
@@ -391,10 +404,7 @@
|
||||
|
||||
- (void)underRightWillAppear
|
||||
{
|
||||
[self addTopViewSnapshot];
|
||||
if (resetStrategy & ECTapping) {
|
||||
[self.topView addGestureRecognizer:self.resetTapGesture];
|
||||
}
|
||||
topViewHasFocus = NO;
|
||||
self.underLeftView.hidden = YES;
|
||||
[self.underRightViewController viewWillAppear:NO];
|
||||
self.underRightView.hidden = NO;
|
||||
@@ -402,9 +412,14 @@
|
||||
|
||||
- (void)topDidReset
|
||||
{
|
||||
topViewHasFocus = YES;
|
||||
[self.topView removeGestureRecognizer:self.resetTapGesture];
|
||||
[self removeTopViewSnapshot];
|
||||
self.panGesture.enabled = YES;
|
||||
}
|
||||
|
||||
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
|
||||
// return YES;
|
||||
//}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//
|
||||
// UIImage+ImageWithUIView.h
|
||||
// Taken from http://stackoverflow.com/a/7233268
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//
|
||||
// UIImage+ImageWithUIView.m
|
||||
// Taken from http://stackoverflow.com/a/7233268
|
||||
//
|
||||
|
||||
#import "UIImage+ImageWithUIView.h"
|
||||
@@ -8,30 +7,17 @@
|
||||
@implementation UIImage (ImageWithUIView)
|
||||
#pragma mark -
|
||||
#pragma mark TakeScreenShot
|
||||
static CGContextRef createBitmapContext(int pixelsWide, int pixelsHigh)
|
||||
{
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
CGBitmapInfo bitmapInfo = (kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
|
||||
CGContextRef bitmapContext = CGBitmapContextCreate(nil, pixelsWide, pixelsHigh, 8, 0, colorSpace, bitmapInfo);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
|
||||
return bitmapContext;
|
||||
}
|
||||
|
||||
+ (UIImage *)imageWithUIView:(UIView *)view
|
||||
{
|
||||
CGSize screenShotSize = view.bounds.size;
|
||||
CGContextRef contextRef = createBitmapContext(screenShotSize.width, screenShotSize.height);
|
||||
CGContextTranslateCTM (contextRef, 0, screenShotSize.height);
|
||||
CGContextScaleCTM(contextRef, 1, -1);
|
||||
UIImage *img;
|
||||
UIGraphicsBeginImageContext(screenShotSize);
|
||||
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
||||
[view drawLayer:view.layer inContext:ctx];
|
||||
img = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
[view.layer renderInContext:contextRef];
|
||||
CGImageRef imageRef = CGBitmapContextCreateImage(contextRef);
|
||||
CGContextRelease(contextRef);
|
||||
|
||||
UIImage *img = [UIImage imageWithCGImage:imageRef];
|
||||
CGImageRelease(imageRef);
|
||||
// return the image
|
||||
return img;
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user