Skip to content

Commit 71139e9

Browse files
committed
Maintain local BOOLs for top view positions
Checking the topView frame relative to the resettedCenter was unreliable. It would not always reset to the same position. This caused the topView to anchor from the reset position while rotating.
1 parent e1b722d commit 71139e9

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ @interface ECSlidingViewController()
2121
@property (nonatomic, unsafe_unretained) CGFloat initialHoizontalCenter;
2222
@property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
2323
@property (nonatomic, strong) UITapGestureRecognizer *resetTapGesture;
24+
@property (nonatomic, unsafe_unretained) BOOL underLeftShowing;
25+
@property (nonatomic, unsafe_unretained) BOOL underRightShowing;
26+
@property (nonatomic, unsafe_unretained) BOOL topViewIsOffScreen;
2427

2528
- (NSUInteger)autoResizeToFillScreen;
2629
- (UIView *)topView;
@@ -81,6 +84,9 @@ @implementation ECSlidingViewController
8184
@synthesize initialHoizontalCenter;
8285
@synthesize panGesture = _panGesture;
8386
@synthesize resetTapGesture;
87+
@synthesize underLeftShowing = _underLeftShowing;
88+
@synthesize underRightShowing = _underRightShowing;
89+
@synthesize topViewIsOffScreen = _topViewIsOffScreen;
8490

8591
- (void)setTopViewController:(UIViewController *)theTopViewController
8692
{
@@ -270,7 +276,7 @@ - (void)anchorTopViewTo:(ECSide)side animations:(void (^)())animations onComplet
270276
if (complete) {
271277
complete();
272278
}
273-
279+
_topViewIsOffScreen = NO;
274280
[self addTopViewSnapshot];
275281
dispatch_async(dispatch_get_main_queue(), ^{
276282
NSString *key = (side == ECLeft) ? ECSlidingViewTopDidAnchorLeft : ECSlidingViewTopDidAnchorRight;
@@ -305,6 +311,7 @@ - (void)anchorTopViewOffScreenTo:(ECSide)side animations:(void(^)())animations o
305311
if (complete) {
306312
complete();
307313
}
314+
_topViewIsOffScreen = YES;
308315
[self addTopViewSnapshot];
309316
dispatch_async(dispatch_get_main_queue(), ^{
310317
NSString *key = (side == ECLeft) ? ECSlidingViewTopDidAnchorLeft : ECSlidingViewTopDidAnchorRight;
@@ -333,21 +340,6 @@ - (void)resetTopViewWithAnimations:(void(^)())animations onComplete:(void(^)())c
333340
}];
334341
}
335342

336-
- (BOOL)underLeftShowing
337-
{
338-
return self.topView.frame.origin.x > 0;
339-
}
340-
341-
- (BOOL)underRightShowing
342-
{
343-
return self.topView.frame.origin.x < 0;
344-
}
345-
346-
- (BOOL)topViewIsOffScreen
347-
{
348-
return self.topView.center.x <= -self.resettedCenter + 1 || self.topView.center.x >= self.screenWidth + self.resettedCenter - 1;
349-
}
350-
351343
- (NSUInteger)autoResizeToFillScreen
352344
{
353345
return (UIViewAutoresizingFlexibleWidth |
@@ -472,6 +464,8 @@ - (void)underLeftWillAppear
472464
[self.underLeftViewController viewWillAppear:NO];
473465
self.underLeftView.hidden = NO;
474466
[self updateUnderLeftLayout];
467+
_underLeftShowing = YES;
468+
_underRightShowing = NO;
475469
}
476470

477471
- (void)underRightWillAppear
@@ -483,6 +477,8 @@ - (void)underRightWillAppear
483477
[self.underRightViewController viewWillAppear:NO];
484478
self.underRightView.hidden = NO;
485479
[self updateUnderRightLayout];
480+
_underLeftShowing = NO;
481+
_underRightShowing = YES;
486482
}
487483

488484
- (void)topDidReset
@@ -493,6 +489,9 @@ - (void)topDidReset
493489
[self.topView removeGestureRecognizer:self.resetTapGesture];
494490
[self removeTopViewSnapshot];
495491
self.panGesture.enabled = YES;
492+
_underLeftShowing = NO;
493+
_underRightShowing = NO;
494+
_topViewIsOffScreen = NO;
496495
}
497496

498497
- (BOOL)topViewHasFocus

0 commit comments

Comments
 (0)