美文网首页
iMoive拖动选择框

iMoive拖动选择框

作者: 风动青春 | 来源:发表于2018-04-19 13:46 被阅读0次

- (void)loadView {

    [super loadView];

    preBgView = [[UIView alloc] initWithFrame:CGRectMake(10, 70, Screen_Width-20, 90)];

    preBgView.backgroundColor = UIColorFromRGB(0x888888);

    [self.view addSubview:preBgView];

    UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanGesture:)];

    [preBgView addGestureRecognizer:panGesture];

    sliderBgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, preBgView.frame.size.width, preBgView.frame.size.height)];

    sliderBgView.layer.borderWidth = 5;

    sliderBgView.layer.borderColor = UIColorFromRGB(999999).CGColor;

    sliderBgView.userInteractionEnabled = YES;

    [preBgView addSubview:sliderBgView];

    leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, sliderBgView.frame.size.height)];

    leftBtn.backgroundColor = [UIColor redColor];

    [sliderBgView addSubview:leftBtn];

    UIPanGestureRecognizer *leftPanGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handleLeftPanGesture:)];

    [leftBtn addGestureRecognizer:leftPanGesture];

    rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(sliderBgView.frame.size.width-20, 0, 20, sliderBgView.frame.size.height)];

    rightBtn.backgroundColor = [UIColor yellowColor];

    [sliderBgView addSubview:rightBtn];

    UIPanGestureRecognizer *rightPanGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handleRightPanGesture:)];

    [rightBtn addGestureRecognizer:rightPanGesture];

}

#pragma mark - Gesture

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

    //得到拖过程中的xy坐标

    CGPoint translation = [(UIPanGestureRecognizer *)sender locationInView:preBgView];

    if(sender.state==UIGestureRecognizerStateChanged) {

        // 根据拖动位置,快进视频预览进度

    }

}

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

    //得到拖过程中的xy坐标

    CGPoint translation = [(UIPanGestureRecognizer *)sender locationInView:preBgView];

    if (translation.x < 0 || sliderBgView.frame.size.width+sliderBgView.frame.origin.x < translation.x+rightBtn.frame.size.width*2 ) {

        return;

    }

    CGFloat intX = translation.x - sliderBgView.frame.origin.x;

    if(sender.state==UIGestureRecognizerStateChanged)

    {

        CGRect rect = sliderBgView.frame;

        rect.origin.x = translation.x;

        rect.size.width = sliderBgView.frame.size.width - intX;

        sliderBgView.frame = rect;

        rect = rightBtn.frame;

        rect.origin.x = sliderBgView.frame.size.width-rightBtn.frame.size.width;

        rightBtn.frame = rect;

    }

}

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

    //得到拖过程中的xy坐标

    CGPoint translation = [(UIPanGestureRecognizer *)sender locationInView:preBgView];

    if (translation.x+rightBtn.frame.size.width >= preBgView.frame.size.width) {

        return;

    }

    CGFloat intX = sliderBgView.frame.size.width+sliderBgView.frame.origin.x - translation.x;

    if(sender.state==UIGestureRecognizerStateChanged)

    {

        CGRect rect = sliderBgView.frame;

        rect.size.width = sliderBgView.frame.size.width - intX;

        sliderBgView.frame = rect;

        rect = rightBtn.frame;

        rect.origin.x = sliderBgView.frame.size.width-rightBtn.frame.size.width;

        rightBtn.frame = rect;

    }

}

相关文章

  • iMoive拖动选择框

    - (void)loadView { [super loadView]; preBgView = [[UIVi...

  • css设置禁止拖拽输入选中 滚动条样式

    input框禁止输入选择 禁止图片文字选中拖动 修改滚动条样式 鼠标光标样式

  • 输入框交互形式

    【教程】: Step1:拖动文字输入框原件至操作面板 【教程】: Step1: 拖动文字输入框原件至操作面板 St...

  • 2017.11.30 AngularJS弹框、FileRead

    第一组:刘聪 AngularJS弹框可拖动功能 框架内的弹框默认是不能拖动,在不改变框架的前提下,可以通过自定义...

  • PS切图小记

    1 拖动图片到PS图层名称栏 2 矩形选择框选择要裁切的矩形框 3 按下delete键,删除不要的部分 4 按V移...

  • 拖动的模态框

    核心原理1、给窗口title绑定鼠标按下事件;2、获取鼠标到login盒子的x,y坐标存为变量(x=e.pageX...

  • 另类好用的文字识别工具_OCR工具

    发送或拖动图片到QQ对话框,在图片上点击右键,选择:提取图中文字。/OCR工具 需要对结果进行校对。 Update...

  • Service创建悬浮框

    首先,介绍下作用,及功能, 利用service创建悬浮框,然后这个悬浮框不能影响界面其他的按键,所以需要拖动,然后...

  • Tabula 1.0.2 表格抽取调研

    Web版 浏览PDF的页面,然后通过单击并拖动绘制一个框来选择表格。 一页PDF多个表格 可识别一页PDF中有多个...

  • PS里的CTRL+T

    Ctrl+T出现变形框后,我们可以按住Ctrl键,拖动角点可以对单个点进行“位移”,拖动线段中间的点,可以进行“斜...

网友评论

      本文标题:iMoive拖动选择框

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