This should be straightforward with UIPanGestureRecognizer and a little math. To change the view to the correct frame (I use the name _viewToChange , so replace it in my opinion 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 a super view and define a method:
- (void)pan:(UIPanGestureRecognizer *)aPan; { CGPoint currentPoint = [aPan locationInView:self]; [UIView animateWithDuration:0.01f animations:^{ 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 as the user's finger moves. Hope this helps!
source share