如何使一个动态UIImage在屏幕上移动?

3

我希望能够在屏幕上移动一个动画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个回答

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更改为您所需的值,以获得动画到不同位置的效果。


即时帮助请访问 http://chat.stackoverflow.com/rooms/682/conversation/do-u-want-instant-help-for-ur-question-or-r-u-new-bee-to-iphone-ipad-develop - Vijay-Apple-Dev.blogspot.com

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接