6
6
// Copyright (c) 2012 EdgeCase. All rights reserved.
7
7
//
8
8
9
+ #define HORIZ_SWIPE_DRAG_MIN 5
9
10
#import " ECSlidingViewController.h"
10
11
11
12
@interface ECSlidingViewController ()
12
13
13
- @property (nonatomic , strong ) UIButton *topViewSnapshot;
14
+ @property (nonatomic , strong ) UIView *topViewSnapshot;
14
15
@property (nonatomic , unsafe_unretained) CGFloat initialTouchPositionX;
15
16
@property (nonatomic , unsafe_unretained) CGFloat initialHoizontalCenter;
16
17
@property (nonatomic , strong ) UIPanGestureRecognizer *panGesture;
@@ -138,6 +139,9 @@ - (void)viewDidLoad
138
139
139
140
- (void )willAnimateRotationToInterfaceOrientation : (UIInterfaceOrientation)toInterfaceOrientation duration : (NSTimeInterval )duration
140
141
{
142
+ if (!topViewHasFocus){
143
+ [self removeTopViewSnapshot ];
144
+ }
141
145
if ([self underRightShowing ] && ![self topViewIsOffScreen ]) {
142
146
[self updateTopViewHorizontalCenter: self .anchorLeftTopViewCenter];
143
147
} else if ([self underRightShowing ] && [self topViewIsOffScreen ]) {
@@ -149,6 +153,12 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte
149
153
}
150
154
}
151
155
156
+ - (void )didRotateFromInterfaceOrientation : (UIInterfaceOrientation)fromInterfaceOrientation {
157
+ if (!topViewHasFocus){
158
+ [self addTopViewSnapshot ];
159
+ }
160
+ }
161
+
152
162
- (void )updateTopViewHorizontalCenterWithRecognizer : (UIPanGestureRecognizer *)recognizer
153
163
{
154
164
CGPoint currentTouchPoint = [recognizer locationInView: self .view];
@@ -210,10 +220,11 @@ - (void)anchorTopViewTo:(ECSide)side animations:(void (^)())animations onComplet
210
220
} else {
211
221
self.panGesture .enabled = NO ;
212
222
}
213
-
214
223
if (complete) {
215
224
complete ();
216
225
}
226
+ topViewHasFocus = NO ;
227
+ [self addTopViewSnapshot ];
217
228
}];
218
229
}
219
230
@@ -238,6 +249,8 @@ - (void)anchorTopViewOffScreenTo:(ECSide)side animations:(void(^)())animations o
238
249
if (complete) {
239
250
complete ();
240
251
}
252
+ topViewHasFocus = NO ;
253
+ [self addTopViewSnapshot ];
241
254
}];
242
255
}
243
256
@@ -246,6 +259,7 @@ - (void)resetTopView
246
259
[UIView animateWithDuration: 0 .25f animations: ^{
247
260
[self updateTopViewHorizontalCenter: self .resettedCenter];
248
261
} completion: ^(BOOL finished) {
262
+ topViewHasFocus = YES ;
249
263
[self topViewHorizontalCenterDidChange: self .resettedCenter];
250
264
}];
251
265
}
@@ -318,16 +332,18 @@ - (void)topViewHorizontalCenterDidChange:(CGFloat)newHorizontalCenter
318
332
- (void )addTopViewSnapshot
319
333
{
320
334
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 ;
323
337
[self .topView addSubview: self .topViewSnapshot];
338
+ [self .topViewSnapshot addGestureRecognizer: self .resetTapGesture];
324
339
}
325
340
}
326
341
327
342
- (void )removeTopViewSnapshot
328
343
{
329
344
if (self.topViewSnapshot .superview ) {
330
345
[self .topViewSnapshot removeFromSuperview ];
346
+ topViewSnapshot = nil ;
331
347
}
332
348
}
333
349
@@ -380,31 +396,30 @@ - (CGFloat)screenWidthForOrientation:(UIInterfaceOrientation)orientation
380
396
381
397
- (void )underLeftWillAppear
382
398
{
383
- [self addTopViewSnapshot ];
384
- if (resetStrategy & ECTapping) {
385
- [self .topView addGestureRecognizer: self .resetTapGesture];
386
- }
399
+ topViewHasFocus = NO ;
387
400
self.underRightView .hidden = YES ;
388
401
[self .underLeftViewController viewWillAppear: NO ];
389
402
self.underLeftView .hidden = NO ;
390
403
}
391
404
392
405
- (void )underRightWillAppear
393
406
{
394
- [self addTopViewSnapshot ];
395
- if (resetStrategy & ECTapping) {
396
- [self .topView addGestureRecognizer: self .resetTapGesture];
397
- }
407
+ topViewHasFocus = NO ;
398
408
self.underLeftView .hidden = YES ;
399
409
[self .underRightViewController viewWillAppear: NO ];
400
410
self.underRightView .hidden = NO ;
401
411
}
402
412
403
413
- (void )topDidReset
404
414
{
415
+ topViewHasFocus = YES ;
405
416
[self .topView removeGestureRecognizer: self .resetTapGesture];
406
417
[self removeTopViewSnapshot ];
407
418
self.panGesture .enabled = YES ;
408
419
}
409
420
421
+ // - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
422
+ // return YES;
423
+ // }
424
+
410
425
@end
0 commit comments