2011-07-27 33 views
3

我想在屏幕上移動動畫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]; 

回答

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到你想要得到各種位置的動畫。

+0

玩得開心........ –

+0

即時幫助http://chat.stackoverflow.com/rooms/682/conversation/do-u-want-instant-help-for-ur-question-或-RU-新蜂到iphone,ipad公司發展 –