- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

 

     UITouch *touch = [touches anyObject];// 某一个手指

    CGPoint currentPoint = [touch locationInView:self.superview]; // 自己相对于父视图的坐标

    CGPoint previousPoint = [touch previousLocationInView:self.superview];

    

    CGFloat dltX = currentPoint.x - previousPoint.x;

    CGFloat dltY = currentPoint.y - previousPoint.y;

    CGPoint center = self.center;    

    CGPoint newCenter = CGPointMake(center.x + dltX, center.y + dltY);    

    self.center = newCenter;

    

     self.backgroundColor = [UIColorcolorWithRed:(arc4random() % 256)/255.0green:(arc4random() % 256)/255.0blue:(arc4random() % 256)/255.0alpha:1.0];

}

 

相关文章:

  • 2021-10-19
  • 2021-10-19
  • 2021-12-23
  • 2021-11-12
  • 2021-06-30
  • 2020-06-10
  • 2021-10-16
  • 2021-10-19
猜你喜欢
  • 2021-12-22
  • 2020-03-15
  • 2021-10-19
  • 2021-12-22
  • 2021-12-02
  • 2021-12-02
  • 2021-12-12
相关资源
相似解决方案