码迷,mamicode.com
首页 > 其他好文 > 详细

UIPanGestureRecognizer 拖动TableView改变其高度

时间:2016-06-10 20:24:09      阅读:954      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!