Skip to content

Commit b4ec054

Browse files
committed
Handle rotation
- need to adjust peekAmount when changing rotation
1 parent be59d93 commit b4ec054

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

ECSlidingViewController/Storyboard.storyboard

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<viewController storyboardIdentifier="Menu" id="Wid-ZD-WEx" customClass="MenuViewController" sceneMemberID="viewController">
1212
<view key="view" contentMode="scaleToFill" id="W0P-Wb-YYH">
1313
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
14-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
14+
<autoresizingMask key="autoresizingMask"/>
1515
<subviews>
1616
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="35U-4J-jxL">
1717
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
@@ -46,7 +46,7 @@
4646
<viewController storyboardIdentifier="ThirdTop" id="LsE-e5-Jbi" customClass="ThirdTopViewController" sceneMemberID="viewController">
4747
<view key="view" contentMode="scaleToFill" id="UCM-3d-Qlw">
4848
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
49-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
49+
<autoresizingMask key="autoresizingMask"/>
5050
<subviews>
5151
<navigationBar contentMode="scaleToFill" id="DZQ-RF-UaR">
5252
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
@@ -74,7 +74,7 @@
7474
<viewController storyboardIdentifier="SecondTop" id="XYc-ji-qQz" customClass="SecondTopViewController" sceneMemberID="viewController">
7575
<view key="view" contentMode="scaleToFill" id="Z4T-qv-OS6">
7676
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
77-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
77+
<autoresizingMask key="autoresizingMask"/>
7878
<subviews>
7979
<navigationBar contentMode="scaleToFill" id="rTR-El-PZX">
8080
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
@@ -183,7 +183,7 @@
183183
<viewController id="H2v-Ob-DhD" customClass="InitialSlidingViewController" sceneMemberID="viewController">
184184
<view key="view" contentMode="scaleToFill" id="IWW-TW-Yeo">
185185
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
186-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
186+
<autoresizingMask key="autoresizingMask"/>
187187
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
188188
</view>
189189
</viewController>

ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ - (void)updateTopViewHorizontalCenterWithRecognizer:(UIPanGestureRecognizer *)re
2626
- (void)updateTopViewHorizontalCenter:(CGFloat)newHorizontalCenter;
2727
- (void)addTopViewSnapshot;
2828
- (void)removeTopViewSnapshot;
29+
- (CGFloat)resettedCenter;
2930
- (CGFloat)screenWidth;
3031
- (CGFloat)screenWidthForOrientation:(UIInterfaceOrientation)orientation;
3132
- (BOOL)underLeftShowing;
@@ -144,8 +145,8 @@ - (void)updateTopViewHorizontalCenterWithRecognizer:(UIPanGestureRecognizer *)re
144145
CGFloat panAmount = self.initialTouchPositionX - currentTouchPositionX;
145146
CGFloat newCenterPosition = self.initialHoizontalCenter - panAmount;
146147

147-
if ((newCenterPosition < self.view.center.x && self.leftSidePeekAmount == NSNotFound) || (newCenterPosition > self.view.center.x && self.rightSidePeekAmount == NSNotFound)) {
148-
newCenterPosition = self.view.center.x;
148+
if ((newCenterPosition < self.resettedCenter && self.leftSidePeekAmount == NSNotFound) || (newCenterPosition > self.resettedCenter && self.rightSidePeekAmount == NSNotFound)) {
149+
newCenterPosition = self.resettedCenter;
149150
}
150151

151152
[self updateTopViewHorizontalCenter:newCenterPosition];
@@ -168,9 +169,9 @@ - (void)slideInDirection:(ECSlideDirection)slideDirection peekAmount:(CGFloat)pe
168169
CGFloat newCenter = self.topView.center.x;
169170

170171
if (slideDirection == ECSlideLeft) {
171-
newCenter = -self.screenWidth + self.view.center.x + peekAmount;
172+
newCenter = -self.screenWidth + self.resettedCenter + peekAmount;
172173
} else if (slideDirection == ECSlideRight) {
173-
newCenter = self.screenWidth + self.view.center.x - peekAmount;
174+
newCenter = self.screenWidth + self.resettedCenter - peekAmount;
174175
}
175176

176177
[UIView animateWithDuration:0.25f animations:^{
@@ -198,7 +199,7 @@ - (void)enablePanningInDirection:(ECSlideDirection)slideDirection forView:(UIVie
198199
- (void)reset
199200
{
200201
[UIView animateWithDuration:0.25f animations:^{
201-
[self updateTopViewHorizontalCenter:self.view.center.x];
202+
[self updateTopViewHorizontalCenter:self.resettedCenter];
202203
}];
203204
}
204205

@@ -231,16 +232,16 @@ - (void)updateTopViewHorizontalCenter:(CGFloat)newHorizontalCenter
231232
{
232233
CGPoint center = self.topView.center;
233234

234-
if (center.x <= self.view.center.x && newHorizontalCenter > self.view.center.x) {
235+
if (center.x <= self.resettedCenter && newHorizontalCenter > self.resettedCenter) {
235236
[self underLeftWillAppear];
236-
} else if (center.x >= self.view.center.x && newHorizontalCenter < self.view.center.x) {
237+
} else if (center.x >= self.resettedCenter && newHorizontalCenter < self.resettedCenter) {
237238
[self underRightWillAppear];
238239
}
239240

240241
center.x = newHorizontalCenter;
241242
self.topView.center = center;
242243

243-
if (newHorizontalCenter == self.view.center.x) {
244+
if (newHorizontalCenter == self.resettedCenter) {
244245
[self topDidReset];
245246
}
246247
}
@@ -261,6 +262,11 @@ - (void)removeTopViewSnapshot
261262
}
262263
}
263264

265+
- (CGFloat)resettedCenter
266+
{
267+
return ceil(self.screenWidth / 2);
268+
}
269+
264270
- (CGFloat)screenWidth
265271
{
266272
return [self screenWidthForOrientation:[UIApplication sharedApplication].statusBarOrientation];

0 commit comments

Comments
 (0)