UIView的拖拽

  做出来效果:屏幕上的一块UIView,点击后能自由移动

 1 #import "GreenView.h"
 2 @implementation GreenView
 3 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
 4 {
 5     UITouch *touch = [touches anyObject];
 6     CGPoint currentP = [touch locationInView:self];
 7     CGPoint previousP = [touch previousLocationInView:self];
 8     CGFloat offsetX = currentP.x - previousP.x;
 9     CGFloat offsetY = currentP.y - previousP.y;
10     self.transform = CGAffineTransformTranslate(self.transform, offsetX, offsetY);
11 }
12 @end

 

posted @ 2016-07-07 19:52  hissia  阅读(408)  评论(1编辑  收藏  举报