2

i am new in iOS development and facing little issue.i don't know this approach is good or bad but i not want to used any third party.I want to make sidebar like Facebook sidebar and my code is

- (IBAction)basicProfile:(id)sender {

    menuViewController *destVC = [self.storyboard instantiateViewControllerWithIdentifier:@"menuView"];


    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    CGRect view = self.view.frame;
    view.origin.x = 280;




    if(self.view.frame.origin.x > 100 )
    {
        [UIView beginAnimations:nil context:(__bridge void *)(self.scrollView)];
        [UIView setAnimationDuration:0.25];
        NSLog(@"%f", self.view.frame.origin.y);
        self.view.frame = CGRectMake(0,0,320,568);
        [UIView commitAnimations];

    }

    else{
        [self.showView setHidden:NO];
    [UIView beginAnimations:nil context:(__bridge void *)(self.scrollView)];
    [UIView setAnimationDuration:0.25];
    NSLog(@"%f", self.view.frame.origin.y);
    self.view.frame = CGRectMake(280,0,320,568);
    [UIView commitAnimations];
        [self.view addSubview:destVC.view]; // this line added menuView to profile view but not on sidebar 
    }
}

i have two uiview in storyborad one is profile and other is menuViewController.why menuView not loaded properly result of above code

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
Haseeb
  • 361
  • 2
  • 20

2 Answers2

0

Step 01: Basically what you need is a viewController and 2 views (1 for sidebar and another the main view.)

Step 02 : You would than require to add both these views to the View Controller.

Step 03 : And than add a button to toggle using below:

-

(void)OnCollapsibleExtenderTouchUpInside
{
   [UIView animateWithDuration:1.0 animations:^{

    [sideBarObj ToggleVuPosition];

    [mainVuObj ToggleVuSize];

 }];

}

Note : There is already a explanation on stack overflow

You can follow this one: Sidebar menu implementation on iOS like Facebook?

If your requirement is different, Do post comment.

Community
  • 1
  • 1
bllakjakk
  • 5,045
  • 1
  • 18
  • 28
0

There are 2 approaches to do this:

  1. Using 2 UIViews on the Same controller. You can add your MenuView along with your view and initial keep it hidden. Use a button to toggle to show/hide the Menu. It will be just like xview.hidden = TRUE / xview.hidden = FALSE to show/hide the view. You can use animation to give it a menu like appearance.

  2. Use a different view controller for MenuDisplay and add it to the current view controllers like [xview addsubView:menuview.view] and [menuview.view removefromsuperview]

Arun Gupta
  • 2,628
  • 1
  • 20
  • 37