- (void)viewDidLoad { imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; image = [UIImage imageNamed:@"apple.png"]; imageView.image = image; [self.view addSubview:imageView]; }
触屏获得接触点的坐标
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; point = [touch locationInView:self.view]; [self imageMoveOne:point.x imageMoveTwo:point.y]; }
开始移动
- (void)imageMoveOne:(CGFloat)x imageMoveTwo:(CGFloat)y { [UIImageView beginAnimations:nil context:NULL]; UIImageView.animationDuration = 5; UIImageView.animationRepeatCount = 0; [imageView setFrame:CGRectMake(x, y, 100, 100)]; [UIImageView commitAnimations]; }