@@ -38,6 +38,9 @@ - (void)_showMasterViewControllerAnimated:(BOOL)animated;
3838- (void )_rightSwipeGestureRecognized : (UISwipeGestureRecognizer *)recognizer ;
3939- (void )_leftSwipeGestureRecognized : (UISwipeGestureRecognizer *)recognizer ;
4040
41+ - (void )_morphMasterViewInAnimated : (BOOL )animated ;
42+ - (void )_morphMasterViewOutAnimated : (BOOL )animated ;
43+
4144@end
4245
4346
@@ -358,46 +361,74 @@ - (void)_unloadDetailsView
358361- (void )_rightSwipeGestureRecognized : (UISwipeGestureRecognizer *)recognizer
359362{
360363 if (recognizer.state == UIGestureRecognizerStateRecognized && !self.isMasterViewVisible ) {
361- CGFloat masterWidth = _splitViewControllerFlags.masterViewControllerWidth ;
362-
363- if (!self.isMasterViewLoaded ) {
364- [self _loadMasterView ];
365-
366- CGPoint center = _masterView.center ;
367- center.x -= masterWidth;
368- _masterView.center = center;
369- [self .view addSubview: _masterView];
370- }
371-
372- _detailsView.userInteractionEnabled = NO ;
373- _masterView.state = CTSplitViewControllerMasterViewStateMorphedIn;
374- [self .view bringSubviewToFront: _masterView];
375-
376- [UIView animateWithDuration: 0 .25f
377- animations: ^{
378- _masterView.frame = CGRectMake (0 .0f , 0 .0f , masterWidth, CGRectGetHeight (self.view .bounds ));
379- } completion: nil ];
364+ [self _morphMasterViewInAnimated: YES ];
380365 }
381366}
382367
383368- (void )_leftSwipeGestureRecognized : (UISwipeGestureRecognizer *)recognizer
384369{
385370 if (recognizer.state == UIGestureRecognizerStateRecognized && self.isMasterViewVisible && _splitViewControllerFlags.masterViewControllerHidden ) {
386- void (^animationBlock)(void ) = ^(void ) {
387- CGFloat masterWidth = self.masterViewControllerWidth ;
388-
389- CGPoint center = _masterView.center ;
390- center.x -= masterWidth;
391- _masterView.center = center;
392- };
393-
394- void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
395- [self _unloadMasterView ];
396- _detailsView.userInteractionEnabled = YES ;
397- };
371+ [self _morphMasterViewOutAnimated: YES ];
372+ }
373+ }
374+
375+ - (void )_morphMasterViewInAnimated : (BOOL )animated
376+ {
377+ CGFloat masterWidth = _splitViewControllerFlags.masterViewControllerWidth ;
378+
379+ if (!self.isMasterViewLoaded ) {
380+ [self _loadMasterView ];
398381
382+ CGPoint center = _masterView.center ;
383+ center.x -= masterWidth;
384+ _masterView.center = center;
385+ [self .view addSubview: _masterView];
386+ }
387+
388+ _masterView.state = CTSplitViewControllerMasterViewStateMorphedIn;
389+ [self .view bringSubviewToFront: _masterView];
390+
391+ void (^animationBlock)(void ) = ^(void ) {
392+ _masterView.frame = CGRectMake (0 .0f , 0 .0f , masterWidth, CGRectGetHeight (self.view .bounds ));
393+ };
394+
395+ void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
396+ _detailsView.userInteractionEnabled = NO ;
397+ };
398+
399+ if (animated) {
399400 [UIView animateWithDuration: 0 .25f animations: animationBlock completion: completionBlock];
401+ } else {
402+ animationBlock ();
403+ completionBlock (YES );
404+ }
405+
406+ [UIView animateWithDuration: 0 .25f
407+ animations: ^{
408+
409+ } completion: nil ];
410+ }
400411
412+ - (void )_morphMasterViewOutAnimated : (BOOL )animated
413+ {
414+ void (^animationBlock)(void ) = ^(void ) {
415+ CGFloat masterWidth = self.masterViewControllerWidth ;
416+
417+ CGPoint center = _masterView.center ;
418+ center.x -= masterWidth;
419+ _masterView.center = center;
420+ };
421+
422+ void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
423+ [self _unloadMasterView ];
424+ _detailsView.userInteractionEnabled = YES ;
425+ };
426+
427+ if (animated) {
428+ [UIView animateWithDuration: 0 .25f animations: animationBlock completion: completionBlock];
429+ } else {
430+ animationBlock ();
431+ completionBlock (YES );
401432 }
402433}
403434
0 commit comments