目录

IOS-UIView的移动

目录

IOS-UIView的移动

  • 1.UIView的移动
  • - (void)initAdditionalControl
    {
        self.moveView = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
        self.moveView.backgroundColor = [UIColor redColor];
        [self.view addSubview:self.moveView];
    }
    
    - (void)touchesMoved:(NSSet<UITouch _> _)touches withEvent:(UIEvent *)event
    {
    UITouch *touch = [touches anyObject];
    CGPoint cup = [touch locationInView:self.moveView];
    CGPoint bef = [touch previousLocationInView:self.moveView];
    self.moveView.transform = CGAffineTransformTranslate(self.moveView.transform, cup.x - bef.x, cup.y - bef.y);
    }