Changing height of UIView in reponse to finger drag

I understand that the title is a bit confusing so I’ll try my best to explain it well. I have a UIView that has a fixed width of 100, and a variable height that starts at 0. What I want to be able to do is drag my finger from the base of the UIView, towards the top of the screen, and the UIView changes its height/extends to the position of my finger. If that’s still to complicated just imagine it as a strip of paper being pulled out from under something.

If you can help, that would be really great. I don’t think it should be too hard, but I’m only a beginner and I can understand if I haven’t explained it well!

  • Why can't you change a UIView background color in drawRect?
  • Resume CABasicAnimation using negative speed?
  • drawRect and addSubview: custom drawing affects which views?
  • Changing a frame in viewDidLayoutSubviews
  • Cannot put a google maps GMSMapView in a subview of main main view?
  • Changing UIView when applicationWillEnterForeground fires
  • Solutions Collect From Internet About “Changing height of UIView in reponse to finger drag”

    This should be straight-forward with a UIPanGestureRecognizer and a little math. To change the view to the correct frame (I’m using the name _viewToChange, so replace that with your view later), simply add:

    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    pan.maximumNumberOfTouches = pan.minimumNumberOfTouches = 1;
    [self addGestureRecognizer:pan];

    to your init method for the super view, and define the method:

    - (void)pan:(UIPanGestureRecognizer *)aPan; {
      CGPoint currentPoint = [aPan locationInView:self];
      [UIView animateWithDuration:0.01f
                         CGRect oldFrame = _viewToChange.frame;
                         _viewToChange.frame = CGRectMake(oldFrame.origin.x, currentPoint.y, oldFrame.size.width, ([UIScreen mainScreen].bounds.size.height - currentPoint.y));

    This should animate the view up as the users finger moves. Hope that Helps!