zoukankan      html  css  js  c++  java
  • UIPanGestureRecognizer 拖动TableView改变其高度

    需求:项目中要求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,这样才能够连续拖动

  • 相关阅读:
    eclipse c++
    smb
    osx mount nfs/smb
    0927用的
    0926 隐藏地址栏
    0921笔记
    生成文件并下载
    在线图标
    react redux
    electron
  • 原文地址:https://www.cnblogs.com/Apple2U/p/5574126.html
Copyright © 2011-2022 走看看