|
28 | 28 | #import "SlideNavigationController.h" |
29 | 29 | #import "SlideNavigationContorllerAnimator.h" |
30 | 30 |
|
| 31 | +typedef enum { |
| 32 | + PopTypeAll, |
| 33 | + PopTypeRoot |
| 34 | +} PopType; |
| 35 | + |
31 | 36 | @interface SlideNavigationController() |
32 | 37 | @property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer; |
33 | 38 | @property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer; |
@@ -171,44 +176,97 @@ - (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion |
171 | 176 | }]; |
172 | 177 | } |
173 | 178 |
|
174 | | -- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion |
| 179 | +- (void)switchToViewController:(UIViewController *)viewController |
| 180 | + withSlideOutAnimation:(BOOL)slideOutAnimation |
| 181 | + popType:(PopType)poptype |
| 182 | + andCompletion:(void (^)())completion |
175 | 183 | { |
176 | 184 | if (self.avoidSwitchingToSameClassViewController && [self.topViewController isKindOfClass:viewController.class]) |
177 | 185 | { |
178 | 186 | [self closeMenuWithCompletion:completion]; |
179 | 187 | return; |
180 | 188 | } |
181 | 189 |
|
182 | | - if ([self isMenuOpen]) |
183 | | - { |
184 | | - [UIView animateWithDuration:MENU_SLIDE_ANIMATION_DURATION |
185 | | - delay:0 |
186 | | - options:UIViewAnimationOptionCurveEaseOut |
187 | | - animations:^{ |
188 | | - CGFloat width = self.horizontalSize; |
189 | | - CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width; |
190 | | - [self moveHorizontallyToLocation:moveLocation]; |
191 | | - } completion:^(BOOL finished) { |
192 | | - |
| 190 | + void (^switchAndCallCompletion)(BOOL) = ^(BOOL closeMenuBeforeCallingCompletion) { |
| 191 | + if (poptype == PopTypeAll) { |
| 192 | + [self setViewControllers:@[viewController]]; |
| 193 | + } |
| 194 | + else { |
193 | 195 | [super popToRootViewControllerAnimated:NO]; |
194 | 196 | [super pushViewController:viewController animated:NO]; |
195 | | - |
| 197 | + } |
| 198 | + |
| 199 | + if (closeMenuBeforeCallingCompletion) |
| 200 | + { |
196 | 201 | [self closeMenuWithCompletion:^{ |
197 | 202 | if (completion) |
198 | 203 | completion(); |
199 | 204 | }]; |
200 | | - }]; |
| 205 | + } |
| 206 | + else |
| 207 | + { |
| 208 | + if (completion) |
| 209 | + completion(); |
| 210 | + } |
| 211 | + }; |
| 212 | + |
| 213 | + if ([self isMenuOpen]) |
| 214 | + { |
| 215 | + if (slideOutAnimation) |
| 216 | + { |
| 217 | + [UIView animateWithDuration:(slideOutAnimation) ? MENU_SLIDE_ANIMATION_DURATION : 0 |
| 218 | + delay:0 |
| 219 | + options:UIViewAnimationOptionCurveEaseOut |
| 220 | + animations:^{ |
| 221 | + CGFloat width = self.horizontalSize; |
| 222 | + CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width; |
| 223 | + [self moveHorizontallyToLocation:moveLocation]; |
| 224 | + } completion:^(BOOL finished) { |
| 225 | + switchAndCallCompletion(YES); |
| 226 | + }]; |
| 227 | + } |
| 228 | + else |
| 229 | + { |
| 230 | + switchAndCallCompletion(YES); |
| 231 | + } |
201 | 232 | } |
202 | 233 | else |
203 | 234 | { |
204 | | - [super popToRootViewControllerAnimated:NO]; |
205 | | - [super pushViewController:viewController animated:YES]; |
206 | | - |
207 | | - if (completion) |
208 | | - completion(); |
| 235 | + switchAndCallCompletion(NO); |
209 | 236 | } |
210 | 237 | } |
211 | 238 |
|
| 239 | +- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion |
| 240 | +{ |
| 241 | + [self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeRoot andCompletion:completion]; |
| 242 | +} |
| 243 | + |
| 244 | +- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController |
| 245 | + withSlideOutAnimation:(BOOL)slideOutAnimation |
| 246 | + andCompletion:(void (^)())completion |
| 247 | +{ |
| 248 | + [self switchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeRoot andCompletion:completion]; |
| 249 | +} |
| 250 | + |
| 251 | +- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController |
| 252 | + withCompletion:(void (^)())completion |
| 253 | +{ |
| 254 | + [self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeRoot andCompletion:completion]; |
| 255 | +} |
| 256 | + |
| 257 | +- (void)popAllAndSwitchToViewController:(UIViewController *)viewController |
| 258 | + withSlideOutAnimation:(BOOL)slideOutAnimation |
| 259 | + andCompletion:(void (^)())completion |
| 260 | +{ |
| 261 | + [self switchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeAll andCompletion:completion]; |
| 262 | +} |
| 263 | + |
| 264 | +- (void)popAllAndSwitchToViewController:(UIViewController *)viewController |
| 265 | + withCompletion:(void (^)())completion |
| 266 | +{ |
| 267 | + [self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeAll andCompletion:completion]; |
| 268 | +} |
| 269 | + |
212 | 270 | - (void)closeMenuWithCompletion:(void (^)())completion |
213 | 271 | { |
214 | 272 | [self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion]; |
|
0 commit comments