做出來效果:屏幕上的一塊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