我点击播放按钮6图像视图将填充按下的图像,我希望它能够查看1,等待1秒,查看2,等待一秒钟等。
我应该添加哪些代码:
[imageview7 setImage:imageview1HG.image];
[imageview8 setImage:imageview2HG.image];
[imageview9 setImage:imageview3HG.image];
[imageview10 setImage:imageview4HG.image];
[imageview11 setImage:imageview5HG.image];
[imageview12 setImage:imageview6HG.image];
我尝试了这个:但它不起作用:
[self performSelector:@selector(GameViewController) withObject:nil afterDelay:1];
希望有人知道再见谢谢
编辑更多地解释我的代码
-(IBAction)play {
[self performSelector:@selector(delay) withObject:nil afterDelay:5.0];
play.enabled=NO;
UIImage *img = [UIImage imageNamed:@""];
if (imageview7.image == nil) {
if([textview.text isEqualToString:labelsText.text]){
-(void)delay {
[imageview7 setImage:imageview1HG.image];
[imageview8 setImage:imageview2HG.image];
[imageview9 setImage:imageview3HG.image];
[imageview10 setImage:imageview4HG.image];
[imageview11 setImage:imageview5HG.image];
[imageview12 setImage:imageview6HG.image];}
}
else {
-(void)delay {
[imageview7 setImage:imageview1H.image];
[imageview8 setImage:imageview2H.image];
[imageview9 setImage:imageview3H.image];
[imageview10 setImage:imageview4H.image];
[imageview11 setImage:imageview5H.image];
[imageview12 setImage:imageview6H.image];}
答案 0 :(得分:2)
我猜你想在延迟之后依次在UIImageView上设置setImage。这是代码。
定义
@interface ViewController : UIViewController
{
NSMutableArray * imageViews;
NSMutableArray * images;
int count;
NSTimer * timer1;
}
-(void)setImageForView:(UIImageView *)imageView withImage:(UIImage *)image;
-(void)update;
-(IBAction)setImageOnViewOneAfterOther;
@end
定义
-(void)setImageForView:(UIImageView *)imageView withImage:(UIImage *)image{
[imageView setImage:image];
}
-(void)update{
if (count < [imageViews count]) {
[self setImageForView:[imageViews objectAtIndex:count] withImage:[images objectAtIndex:count]];
count ++;
}else{
[timer1 invalidate];
}
}
-(IBAction)setImageOnViewOneAfterOther{
count = 0;
imageViews = [[NSMutableArray alloc] initWithObjects:img1v,img2v,img3v,img4v,img5v,img6v, nil]; // Set of all UIImageViews
images = [[NSMutableArray alloc] initWithObjects:img1,img2,img3,img4,img5,img6, nil];//Set of all UIImage's where img = [UIImage imageNamed:@"someImage1.png"];
timer1 = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(update) userInfo:nil repeats:YES];
}
答案 1 :(得分:0)
为什么不动画呢?
UIImageView* animatedImageView = [[UIImageView alloc]init];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.gif"],
[UIImage imageNamed:@"2.gif"],
[UIImage imageNamed:@"3.gif"],
[UIImage imageNamed:@"4.gif"], nil]; //etc
animatedImageView.animationDuration = float([animatedImageView.animationImages count]);
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];