---
title: "实现UIImage的移动动画"
author: "helmsman_xcode"
date: "2011-08-16T09:28:46Z"
tags: []
categories: ["移动开发"]
slug: "uiimage"
draft: false
lastmod: "2011-08-16T09:31:14Z"
id: 1150119
url: "https://helmsman-xcode.iteye.com/blog/1150119"
---

```
- (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];
    
}
```