博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios创建可拖动的视图
阅读量:7044 次
发布时间:2019-06-28

本文共 801 字,大约阅读时间需要 2 分钟。

  hot3.png

  在触摸屏幕的时候,触摸点的位置是十分重要的信息。得到的位置坐标是和它所处的试图或窗口相关的坐标。调用触摸对象的locationInView:方法即可,查找到触摸点在指定视图上的位置,就把视图对象传递进去。对自定义视图对象来说,这里调用[touch locationInView:self.view]来获得触摸在本视图上的位置。如果指定为nil,则返回触摸点在窗口的位置。

CGPoint originalLocation;   //全局变量 用于存储起始位置-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    UITouch *touch = [touches   anyObject];    originalLocation = [touch locationInView:self.view];    }-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{    UITouch *touch = [touches anyObject];    CGPoint currentLocation = [touch locationInView:self.view];    CGRect frame = self.view.frame;    frame.origin.x += currentLocation.x - originalLocation.x;    frame.origin.y += currentLocation.y - originalLocation.y;        self.view.frame = frame;  }

转载于:https://my.oschina.net/mjRao/blog/81237

你可能感兴趣的文章
我的友情链接
查看>>
关于基于Annotation的Advice
查看>>
others powercli scripts1
查看>>
python 类 五 : 多重继承的MRO顺序
查看>>
Asp.net 数据库链接字符串 备份一下
查看>>
CentOS系统安装详细步骤
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Shell脚本之测试及条件表达式简述
查看>>
JavaScript函数详解(二)
查看>>
X9BYOD集群界面展示
查看>>
WebsitePanel部署指南
查看>>
Python 字符串格式化 (%操作符)
查看>>
C++右值引用
查看>>
win7远程桌面连接不上,解决办法
查看>>
优秀设计师是怎样炼成的?转自站酷 – 自由的猞猁 创作
查看>>
应用程序池配置隔离
查看>>
RHEL 7服务控制
查看>>
工具控
查看>>
网摘-U盘装XP,U盘装Ubuntu
查看>>