Skip to content

Commit baea000

Browse files
author
Mike Enriquez + Leon Gersing
committed
Merge branch 'snapshot_performance'
2 parents 9692195 + 08b004c commit baea000

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ typedef enum {
2828
} ECResetStrategy;
2929

3030
/** 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. */
31-
@interface ECSlidingViewController : UIViewController
31+
@interface ECSlidingViewController : UIViewController{
32+
CGPoint startTouchPosition;
33+
BOOL topViewHasFocus;
34+
}
3235

3336
/** Returns the view controller that will be visible when the top view is slide to the right.
3437

ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
// Copyright (c) 2012 EdgeCase. All rights reserved.
77
//
88

9+
#define HORIZ_SWIPE_DRAG_MIN 5
910
#import "ECSlidingViewController.h"
1011

1112
@interface ECSlidingViewController()
1213

13-
@property (nonatomic, strong) UIButton *topViewSnapshot;
14+
@property (nonatomic, strong) UIView *topViewSnapshot;
1415
@property (nonatomic, unsafe_unretained) CGFloat initialTouchPositionX;
1516
@property (nonatomic, unsafe_unretained) CGFloat initialHoizontalCenter;
1617
@property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
@@ -138,6 +139,9 @@ - (void)viewDidLoad
138139

139140
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
140141
{
142+
if(!topViewHasFocus){
143+
[self removeTopViewSnapshot];
144+
}
141145
if ([self underRightShowing] && ![self topViewIsOffScreen]) {
142146
[self updateTopViewHorizontalCenter:self.anchorLeftTopViewCenter];
143147
} else if ([self underRightShowing] && [self topViewIsOffScreen]) {
@@ -149,6 +153,12 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte
149153
}
150154
}
151155

156+
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
157+
if(!topViewHasFocus){
158+
[self addTopViewSnapshot];
159+
}
160+
}
161+
152162
- (void)updateTopViewHorizontalCenterWithRecognizer:(UIPanGestureRecognizer *)recognizer
153163
{
154164
CGPoint currentTouchPoint = [recognizer locationInView:self.view];
@@ -210,10 +220,11 @@ - (void)anchorTopViewTo:(ECSide)side animations:(void (^)())animations onComplet
210220
} else {
211221
self.panGesture.enabled = NO;
212222
}
213-
214223
if (complete) {
215224
complete();
216225
}
226+
topViewHasFocus = NO;
227+
[self addTopViewSnapshot];
217228
}];
218229
}
219230

@@ -238,6 +249,8 @@ - (void)anchorTopViewOffScreenTo:(ECSide)side animations:(void(^)())animations o
238249
if (complete) {
239250
complete();
240251
}
252+
topViewHasFocus = NO;
253+
[self addTopViewSnapshot];
241254
}];
242255
}
243256

@@ -246,6 +259,7 @@ - (void)resetTopView
246259
[UIView animateWithDuration:0.25f animations:^{
247260
[self updateTopViewHorizontalCenter:self.resettedCenter];
248261
} completion:^(BOOL finished) {
262+
topViewHasFocus = YES;
249263
[self topViewHorizontalCenterDidChange:self.resettedCenter];
250264
}];
251265
}
@@ -318,16 +332,18 @@ - (void)topViewHorizontalCenterDidChange:(CGFloat)newHorizontalCenter
318332
- (void)addTopViewSnapshot
319333
{
320334
if (!self.topViewSnapshot.superview && !self.shouldAllowUserInteractionsWhenAnchored) {
321-
self.topViewSnapshot = [[UIButton alloc] initWithFrame:self.topView.bounds];
322-
[self.topViewSnapshot setImage:[UIImage imageWithUIView:self.topView] forState:(UIControlStateNormal | UIControlStateHighlighted | UIControlStateSelected)];
335+
self.topViewSnapshot = [[UIView alloc] initWithFrame:self.topView.bounds];
336+
topViewSnapshot.layer.contents = (id)[UIImage imageWithUIView:self.topView].CGImage;
323337
[self.topView addSubview:self.topViewSnapshot];
338+
[self.topViewSnapshot addGestureRecognizer:self.resetTapGesture];
324339
}
325340
}
326341

327342
- (void)removeTopViewSnapshot
328343
{
329344
if (self.topViewSnapshot.superview) {
330345
[self.topViewSnapshot removeFromSuperview];
346+
topViewSnapshot = nil;
331347
}
332348
}
333349

@@ -380,31 +396,30 @@ - (CGFloat)screenWidthForOrientation:(UIInterfaceOrientation)orientation
380396

381397
- (void)underLeftWillAppear
382398
{
383-
[self addTopViewSnapshot];
384-
if (resetStrategy & ECTapping) {
385-
[self.topView addGestureRecognizer:self.resetTapGesture];
386-
}
399+
topViewHasFocus = NO;
387400
self.underRightView.hidden = YES;
388401
[self.underLeftViewController viewWillAppear:NO];
389402
self.underLeftView.hidden = NO;
390403
}
391404

392405
- (void)underRightWillAppear
393406
{
394-
[self addTopViewSnapshot];
395-
if (resetStrategy & ECTapping) {
396-
[self.topView addGestureRecognizer:self.resetTapGesture];
397-
}
407+
topViewHasFocus = NO;
398408
self.underLeftView.hidden = YES;
399409
[self.underRightViewController viewWillAppear:NO];
400410
self.underRightView.hidden = NO;
401411
}
402412

403413
- (void)topDidReset
404414
{
415+
topViewHasFocus = YES;
405416
[self.topView removeGestureRecognizer:self.resetTapGesture];
406417
[self removeTopViewSnapshot];
407418
self.panGesture.enabled = YES;
408419
}
409420

421+
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
422+
// return YES;
423+
//}
424+
410425
@end

ECSlidingViewController/Vendor/ECSlidingViewController/UIImage+ImageWithUIView.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//
22
// UIImage+ImageWithUIView.h
3-
// Taken from http://stackoverflow.com/a/7233268
43
//
54

65
#import <UIKit/UIKit.h>
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
//
22
// UIImage+ImageWithUIView.m
3-
// Taken from http://stackoverflow.com/a/7233268
43
//
54

65
#import "UIImage+ImageWithUIView.h"
76

87
@implementation UIImage (ImageWithUIView)
98
#pragma mark -
109
#pragma mark TakeScreenShot
11-
static CGContextRef createBitmapContext(int pixelsWide, int pixelsHigh)
12-
{
13-
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
14-
CGBitmapInfo bitmapInfo = (kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
15-
CGContextRef bitmapContext = CGBitmapContextCreate(nil, pixelsWide, pixelsHigh, 8, 0, colorSpace, bitmapInfo);
16-
CGColorSpaceRelease(colorSpace);
17-
18-
return bitmapContext;
19-
}
2010

2111
+ (UIImage *)imageWithUIView:(UIView *)view
2212
{
2313
CGSize screenShotSize = view.bounds.size;
24-
CGContextRef contextRef = createBitmapContext(screenShotSize.width, screenShotSize.height);
25-
CGContextTranslateCTM (contextRef, 0, screenShotSize.height);
26-
CGContextScaleCTM(contextRef, 1, -1);
27-
28-
[view.layer renderInContext:contextRef];
29-
CGImageRef imageRef = CGBitmapContextCreateImage(contextRef);
30-
CGContextRelease(contextRef);
14+
UIImage *img;
15+
UIGraphicsBeginImageContext(screenShotSize);
16+
CGContextRef ctx = UIGraphicsGetCurrentContext();
17+
[view drawLayer:view.layer inContext:ctx];
18+
img = UIGraphicsGetImageFromCurrentImageContext();
19+
UIGraphicsEndImageContext();
3120

32-
UIImage *img = [UIImage imageWithCGImage:imageRef];
33-
CGImageRelease(imageRef);
34-
// return the image
3521
return img;
3622
}
3723
@end

0 commit comments

Comments
 (0)