UI_拖动View
2015-07-03 12:44
295 查看
方法一
在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; }
相关文章推荐
- 以 DirectUI 方式实现的ImageButton
- androidstuido使用问题总结一
- UI_触摸事件
- 纯UILabel实现文字的竖排显示
- 继承UILabel类实现Label竖直对齐
- hdu 1908 double queues
- Absolute paths & require()
- 获取运行中的TeamViewer的账号和密码(Test on English GUI)
- hibernate : No positional parameters in query 错误解决办法
- IOS开发学习笔记——UITabBarController
- [tarjan] hdu 3836 Equivalent Sets
- Android 建造者(Builder)模式
- 如何使用NSOperations和NSOperationQueues(二)
- 设计模式读书笔记:Builder(建造者)
- UEFI是什么?与BIOS的区别在哪里?UEFI详解!
- iOS UINavgationController、 UINavigationBar、 UINavigationItem关系分析
- 自已实现一个UI库-实现Windows的一个模拟器
- 自已实现一个UI库-实现画图API接口
- emulator: ERROR: x86 emulation currently requires hardware acceleration!Please ensure Intel HAXM is
- UITabbar 显示小红点 (消息提示)