IOS – 多个图像缓慢向上的animation
我是IOS编程新手。 我想要的是我想显示多个图像,然后他们不断向上,然后重复一遍又一遍循环。 我怎样才能做到这一点 ?
我有总共8个图像,我想要这样展示
我不知道如何添加8个图像,然后他们向上的方向,不断重复。 请在这帮助我。 如果有任何相关的教程,然后请分享
你不应该这样做。 如果你的步数值足够小,以便顺利移动,它将会太慢。
你想使用UIViewanimation。 看看animateWithDuration:animations:
的方法animateWithDuration:animations:
和它的变化)
您的代码可能如下所示:
#define K_AMOUNT_TO_MOVE -(void)moveImages { [UIView animateWithDuration: 2.0 animations: ^ { for(int i=0;i<images.count;i++) { UIImageView *MyImage = images[i]; MyImage.center = CGPointMake (MyImage.center.x, MyImage.center.y- K_AMOUNT_TO_MOVE); } } ]; }
这个基本方法有一些变化,它们会自动反转animation,使其重复,将时间更改为线性,而不是默认的缓入,缓出等等。看一下animateWithDuration:delay:options:animations:completion:
方法animateWithDuration:delay:options:animations:completion:
在Xcode文档中。
//create an array of images in teh ViewController.h file @interface ViewController : UIViewController { UIImageView *images[8]; } //in your viewDidLoad method in teh Viewcontroller.m add [self moveImages]; //add this method to ur ViewController.m -(void)moveImages { for(int i=0;i<images.count;i++) { UIImageView *MyImage = images[i]; UIImageView *MyImage = [[UIImageView aloc] initWithImage:[UIImage imageNamed:@"ur image name"]; MyImage.center = CGPointMake (MyImage.center.x, MyImage.center.y-10); } [self performSelector:@selector(moveImages) withObject:nil afterDelay:0.5]; }