首页 > 其他 > 详细

UIPanGestureRecognizer 拖动TableView改变其高度

时间:2016-06-10 20:23:20      阅读:166      评论:0      收藏:0      [点我收藏+]

需求:项目中要求tableView的高度随着手拖动的位置而改变如下图:

技术分享

关键代码如下:

- (void)viewDidLoad{

 panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(toHandlePanAction:)];

    [self.searchResultView addGestureRecognizer: panGestureRecognizer];

}

- (void)toHandlePanAction:(UIPanGestureRecognizer *)sender {

    CGPoint point = [sender translationInView:self.view];

    CGRect frame = self.searchResultView.frame;

    frame.origin.y = frame.origin.y + point.y;

    frame.size.height = frame.size.height - point.y;

    

    self.searchResultView.frame = frame;

    [ sender setTranslation: CGPointMake(0, 0) inView: self.view ];

}

 //[sender translationInView:self.view] 返回的是距离上次拖动位置的x,y的偏差值

//[ sender setTranslationCGPointMake(00inViewself.view ] 在拖动过程中会连续回调toHandlePanAction这个方法,

然后要重置上一次的拖动位置的偏移量为0,这样才能够连续拖动

 

UIPanGestureRecognizer 拖动TableView改变其高度

原文:http://www.cnblogs.com/Apple2U/p/5574126.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!