Advertisement
thieumao

slidemenu test

Jul 8th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2.  
  3. #import "ContainerViewController.h"
  4. #import "LeftSettingViewController.h"
  5. #import "RoundViewController.h"
  6. @implementation ContainerViewController
  7. @synthesize subViewControllers, isOpeningLeftSettingVC;
  8. - (void)viewDidLoad {
  9.     [super viewDidLoad];
  10.     LeftSettingViewController *leftVC = [[LeftSettingViewController alloc] initWithNibName:@"LeftSettingViewController" bundle:nil];
  11.    
  12.     RoundViewController *roundVC = [[RoundViewController alloc] initWithNibName:@"RoundViewController" bundle:nil];
  13.    
  14.     subViewControllers = @[roundVC, leftVC];
  15. }
  16. -(void)viewWillAppear:(BOOL)animated{
  17.     [super viewWillAppear:animated];
  18.     isOpeningLeftSettingVC = NO;
  19.     RoundViewController *roundVC = (RoundViewController*)subViewControllers.firstObject;
  20.     [self addChildViewController:roundVC];
  21.     roundVC.view.frame = self.view.frame;
  22.     [self.view addSubview:roundVC.view];
  23.     [roundVC didMoveToParentViewController:self];
  24. }
  25. -(void)transitionLeftSettingVC{
  26.    
  27.     if (!isOpeningLeftSettingVC) {
  28.         RoundViewController *roundVC = (RoundViewController*)subViewControllers.firstObject;
  29.         LeftSettingViewController *leftVC = (LeftSettingViewController*)subViewControllers.lastObject;
  30.         [self addChildViewController:leftVC];
  31.             leftVC.view.frame = CGRectMake(-self.view.bounds.size.width/3, 0, self.view.bounds.size.width/3, self.view.bounds.size.height);
  32.         [UIView animateWithDuration:0.5 delay:0.2 options:UIViewAnimationOptionLayoutSubviews animations:^{
  33.             leftVC.view.frame = CGRectMake(0, 0, self.view.bounds.size.width/3, self.view.bounds.size.height);
  34.             roundVC.view.frame = CGRectMake(self.view.bounds.size.width/3, 0, self.view.bounds.size.width * 2/3, self.view.bounds.size.height);
  35.             [self.view addSubview:leftVC.view];
  36.  
  37.         } completion:^(BOOL finished) {
  38.             [leftVC didMoveToParentViewController:self];
  39.         }];
  40.         isOpeningLeftSettingVC = YES;
  41.        
  42.     }else{
  43.         RoundViewController *roundVC = (RoundViewController*)subViewControllers.firstObject;
  44.         LeftSettingViewController *leftVC = (LeftSettingViewController*)subViewControllers.lastObject;
  45.         [leftVC willMoveToParentViewController:nil];
  46.         [UIView animateWithDuration:0.5 delay:0.2 options:UIViewAnimationOptionLayoutSubviews animations:^{
  47.             roundVC.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  48.             leftVC.view.frame = CGRectMake(-self.view.bounds.size.width/3, 0, self.view.bounds.size.width/3, self.view.bounds.size.height);
  49.         } completion:^(BOOL finished) {
  50.             [leftVC removeFromParentViewController];
  51.             [leftVC.view removeFromSuperview];
  52.         }];
  53.         isOpeningLeftSettingVC = NO;
  54.  
  55.     }
  56. }
  57. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement