title: Slide out viewcontroller from right of screen
body: <p>I want to create a slide out menu from the right of my main view controller. However I want the slide out menu to appear on top of the main view and not push it to one side. </p>
  
  <p>I've looked at ECSlidingViewController 2 and it allows sliding out from either side, however the slide out menus appear cut off on the exposed edges. It creates the effect of the top view controller moving left or right to reveal the hidden menu under it. I want it to appear that the hidden menu sliding out is going onto of the main view controller and that we can see its left edge so no content is cut off. </p>
  
  <p>Is this at all possible and would ECSlidingViewController 2 work for this?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is what I have tried:</p>
  
  <p>To detect the touch started:</p>
  
  <pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  
      BBAppDelegate *myAppDelegate = (BBAppDelegate*)[UIApplication sharedApplication].delegate;
  
      UITouch *touch = [[event allTouches] anyObject];
      CGPoint touchLocation = [touch locationInView:self.view];
      NSArray *myViewArray = [[NSBundle mainBundle] loadNibNamed:@"FilterView" owner:self options:nil];
      self.filterView = myViewArray[0];
  
  
      [myAppDelegate.window addSubview:self.filterView];
  
      if (CGRectContainsPoint(self.filterView.frame, touchLocation)) {
  
          dragging = YES;
          oldX = touchLocation.x;
          oldY = touchLocation.y;
      }
  }
  </code></pre>
  
  <p>And then dragging: </p>
  
  <pre><code>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  
      UITouch *touch = [[event allTouches] anyObject];
      CGPoint touchLocation = [touch locationInView:self.view];
  
      if (dragging) {
  
          CGRect frame = self.filterView.frame;
          frame.origin.x = self.filterView.frame.origin.x + touchLocation.x;
          frame.origin.y =  self.filterView.frame.origin.y + touchLocation.y;
          self.filterView.frame = frame;
      }
  }
  </code></pre>
  
  <p>However, when I start a touch, the filterView replaces all views and doesn't slide or animate in anyway. I though it was due to not providing a starting point - so I instated self.filterView like so: </p>
  
  <p>self.filterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 120, 564)];</p>
  
  <p>However changing these values have no effect on the position / size of the view when its displayed. </p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Okay, I started a new project for testing and managed to get a view on screen to move around by following my touches. </p>
  
  <p>I am using <code>UIPanGestureRecognizer</code></p>
  
  <p>Like so:</p>
  
  <pre><code>viewDidLoad
  
  - (void)viewDidLoad
  </code></pre>
  
  <p>{
      [super viewDidLoad];</p>
  
  <pre><code>NSArray *myViewArray = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];
  UIView *myView = myViewArray[0];
  
  self.filterView = myView;
  
  self.filterView.frame = CGRectMake(100, 100, 200, 200);
  
  UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self
                                                                       action:@selector(dragging:)];
  pan.delegate = self;
  
  [self.filterView addGestureRecognizer:pan];
  
  
  [self.view addSubview:self.filterView];
  </code></pre>
  
  <p>}</p>
  
  <p>Then in the dragging method:</p>
  
  <pre><code>-(void)dragging:(UIPanGestureRecognizer *)gesture
  {
      if(gesture.state == UIGestureRecognizerStateBegan)
          {
              NSLog(@"Received a pan gesture");
          self.panCoord = [gesture locationInView:gesture.view];
  
  
          }
      CGPoint newCoord = [gesture locationInView:gesture.view];
      float dX = newCoord.x-self.panCoord.x;
  
  
      gesture.view.frame = CGRectMake(gesture.view.frame.origin.x+dX, gesture.view.frame.origin.y, gesture.view.frame.size.width, gesture.view.frame.size.height);
  }
  </code></pre>
  
  <p>This allows the view to move horizontally only. </p>
  
  <p>Almost there - what I am trying to figure out now is getting it to snap to a location when the user lifts their finger. And how to move this view when its start position is off screen. </p>
  
  <p><strong>Edit 3</strong></p>
  
  <p>Okay, so I wanted to control the speed and velocity of the view coming out onto screen. If the user swipes quickly, the view goes into place at the speed they swipe. If they swipe slowly, it goes into place slowly. However I also set the lowest time - so if they take a long time - it defaults to the min amount. </p>
  
  <p>Here is the code: </p>
  
  <pre><code>{
     float start;
      float end;
  
      NSDate *methodStart;
      NSDate *methodEnd;
  
  }
  
  
  
  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  
  methodStart = [NSDate date];
  
  UITouch *touch = [touches anyObject];
  CGPoint location = [touch locationInView:touch.view];
  
  start = location.x;}
  
  
  -(void)dragging:(UIPanGestureRecognizer *)gesture{
  
  if(gesture.state == UIGestureRecognizerStateBegan)
      {
  
      self.panCoord = [gesture locationInView:gesture.view];
  
  
      }
  
  CGPoint newCoord = [gesture locationInView:gesture.view];
  float dX = newCoord.x-self.panCoord.x;
  
  
  
  
  
  gesture.view.frame = CGRectMake(gesture.view.frame.origin.x+dX, gesture.view.frame.origin.y, gesture.view.frame.size.width, gesture.view.frame.size.height);
  
  
  if (gesture.state == UIGestureRecognizerStateEnded){
  
      methodEnd = [NSDate date];
      NSTimeInterval executionTime = [methodEnd timeIntervalSinceDate:methodStart];
  
  
      double time = executionTime;
  
      float distance = start - end;
  
  
      int distanceOverTime = distance / time;
      float veloticty = distanceOverTime / 100;
  
      double miniTimeToUse = 0.5;
      double newMinTime;
      if (time &lt; miniTimeToUse){
  
          newMinTime =  miniTimeToUse;
      }else {
          newMinTime = time;
      }
  
  
      if (gesture.view.frame.origin.x+dX &gt;= 180){
  
          [UIView animateWithDuration:newMinTime
                                delay:0
               usingSpringWithDamping:0.9
                initialSpringVelocity:veloticty
                              options:0
                           animations:^{
  
                               self.filterView.frame = CGRectMake(300, 100, 200, 200);
  
                           } completion:nil];
  
      }
      if (gesture.view.frame.origin.x+dX &lt;= 181){
  
      [UIView animateWithDuration:newMinTime
      delay:0
      usingSpringWithDamping:0.9
      initialSpringVelocity:veloticty
      options:0
      animations:^{
  
          self.filterView.frame = CGRectMake(50, 100, 200, 200);
  
      } completion:nil];
  
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now just to get it to work on pulling the view off from the side. </p>