ITeye博客

实现UIImage的移动动画

helmsman_xcode · 2011-08-16 09:28 · ios-综合基础文章 · 移动开发 · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。