zoukankan      html  css  js  c++  java
  • UI_拖动View

    方法一

    在touchesMoved中

         // 获取到触摸的手指
         UITouch *touch = [touches anyObject]; // 获取集合中对象
         // 获取開始时的触摸点
         CGPoint previousPoint = [touch previousLocationInView:self];
         // 获取当前的触摸点
         CGPoint latePoint = [touch locationInView:self];
         // 获取当前点的位移量
         CGFloat dx = latePoint.x - previousPoint.x;
         CGFloat dy = latePoint.y - previousPoint.y;
         // 获取当前视图的center
         CGPoint center = self.center;
         // 依据位移量改动center的值
         center.x += dx;
         center.y += dy;
         // 把新的center赋给当前视图
         self.center = center;

    方法二

    #pragma mark - 重写方法
    #pragma mark 触摸開始
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        self.startPoint = [touch locationInView:self];
    
        NSLog(@"%s",__FUNCTION__);
    }
    
    #pragma mark - 触摸移动
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"%s",__FUNCTION__);
    
        // 实现touchview随手势移动
    
        UITouch *touch = [touches anyObject];
        self.endPoint = [touch locationInView:self];
        CGFloat x = _endPoint.x - _startPoint.x;
        CGFloat y = _endPoint.y - _startPoint.y;
    
        CGPoint center = self.center;
    
        center.x += x;
        center.y += y;
        self.center = center;
    }
  • 相关阅读:
    flask全栈开发3 模板
    flask全栈开发2 URL与视图
    flask全栈开发1 课程简介
    微信公众号开发中遇到的问题总结
    python web学习路线
    内存数据库Memcached和redis基本使用
    2019年8月12号成长题目
    2019年8月10号成长题目
    2019年8月7号成长题目
    SpringCloud简介与5大常用组件
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5204400.html
Copyright © 2011-2022 走看看