美文网首页
iOS 模仿猿题库拖拽改变控件的高度

iOS 模仿猿题库拖拽改变控件的高度

作者: LFBoys | 来源:发表于2018-04-12 14:41 被阅读154次

看到猿题库题型是可以上拉下拉,方便查看更多内容。
下载地址
实现结果:

image

通过给控件添加UIPanGestureRecognizer手势

主要实现方法如下:

- (void)dragAction:(UIPanGestureRecognizer *)pan
{
    if (pan.state == UIGestureRecognizerStateBegan) {

        // 用来保存初始高度
        _yyy = CGRectGetMaxY(_topTextView.frame);

    }else if (pan.state == UIGestureRecognizerStateChanged) {

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

        CGFloaty = point.y+_yyy;

        // 底部scrollview最小高度
        if(y >kScreenHeight-150.0) {

            y =kScreenHeight-150.0;

        }

        // 顶部scrollview最小高度
        if(y <100.0) {

            y =100.0;

        }

        // 根据拖动的位置,计算视图的高度
        self.topTextView.frame=CGRectMake(0,0,kScreenWidth, y);
        self.dragLabel.frame=CGRectMake(0, y,kScreenWidth,40);
        self.bottomScroll.frame = CGRectMake(0, CGRectGetMaxY(self.dragLabel.frame), kScreenWidth, kScreenHeight-y-40);

    }else if (pan.state == UIGestureRecognizerStateEnded) {

    }
}

相关文章

网友评论

      本文标题:iOS 模仿猿题库拖拽改变控件的高度

      本文链接:https://www.haomeiwen.com/subject/nenxkftx.html