如何在屏幕上移动动画UIImage?

时间:2011-07-27 13:28:24

标签: iphone ios cocoa-touch uiimage

我想在屏幕上移动动画UIImage。这怎么可能?

到目前为止,我的代码是UIImage动画:

self.myImageWalk.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"img01.png"],[UIImage imageNamed:@"img02.png"], [UIImage imageNamed:@"img03.png"], [UIImage imageNamed:@"img04.png"], nil];

[self.myImageWalk setAnimationRepeatCount:5];
[self.myImageWalk setAnimationDuration:2];
[self.myImageWalk startAnimating];

1 个答案:

答案 0 :(得分:3)

声明此函数.h文件

-(void)doAnimate:(CGRect)rect;

.m文件

-(void)doAnimate:(CGRect)rect{


    [UIView animateWithDuration:2.0 delay:0.5 options:UIViewAnimationCurveEaseInOut animations:^() {


        self.myImageWalk.frame=rect;


    } completion:^(BOOL finished) {

        NSLog(@"animation Done");
    }];


}

然后调用你想要动画的地方

     [self doAnimate:CGRectMake(300, 300, self.myImageWalk.frame.size.width, self.myImageWalk.frame.size.height)];

这里改变300,300你希望得到各种位置的动画。