UIView的拖拽
2016-03-03 21:15
344 查看
1.
2.
2.
// // RedView.m #import "RedView.h" @implementation RedView /** * 当手指在View上移动就会调用 */ -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { // 取出UITouch对象 UITouch *touch = [touches anyObject]; // 获取当前触摸点 CGPoint currentP = [touch locationInView:self]; // 获取上一个触摸点 CGPoint previousP = [touch previousLocationInView:self]; // 获取偏移量 CGFloat offsetX = currentP.x - previousP.x; CGFloat offsetY = currentP.y - previousP.y; // 修改View的位置(frame\center\transform) self.transform = CGAffineTransformTranslate(self.transform, offsetX, offsetY); } @end演示效果:
相关文章推荐
- 多语言Values
- xib自定义UIView报错误 "forUndefinedKey:]: this class is not key value coding-compliant for the key"
- android sdk中tools混淆插件proguardgui.bat简单说明
- UIImagePickerViewController裁切头像
- Educational Codeforces Round 9-D. Longest Subsequence(筛选法)
- UICollectionView-集合视图(理论篇)
- iOS UITableView相关成员方法详解
- HDU 4010 Query on The Trees
- String、StringBuilder、StringBuffer的区别
- SPOJ QTREE - Query on a tree
- question_015-JAVA之Map的遍历方式
- String 与StringBuilder
- Class Of Marquee Scroll通用不间断滚动JS脚本
- ProcessBuilder中如何为命令行传参
- UI控件初始化问题:initWithFrame和initWithCoder、aweakFromNib的执行
- 谈谈UIView的几个layout方法-layoutSubviews、layoutIfNeeded、setNeedsLayout
- spoj 2319 BIGSEQ - Sequence
- Sphinx Building Docs in horizon
- UIView - animateWithDuration 手势动画 使用详解
- 关于IList、IQueryable、IEnumerable与Func、Expression的关系