将UIView的高度改变为手指拖动

我知道这个标题有点混乱,所以我会尽力解释清楚。 我有一个固定的宽度为100的UIView和一个从0开始的variables高度。我想要做的就是将我的手指从UIView的底部拖到屏幕的顶部,UIView改变其高度/延伸到我的手指的位置。 如果这还是复杂的,那就把它想象成一个纸条被从某种东西下拉出来。

如果你能帮上忙,那真是太好了。 我不认为这应该太难,但我只是一个初学者,我可以理解,如果我没有解释得好!

这应该是一个UIPanGestureRecognizer和一个小math简单。 要将视图更改为正确的框架(我正在使用名称_viewToChange ,因此稍后将其replace为您的视图),只需添加:

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

到超级视图的init方法,并定义方法:

 - (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)); }]; } 

这应该在用户手指移动时使视图animation化。 希望帮助!