Objective c 如何一个接一个地显示图像
我目前正在遍历一个列表,根据元素的条件,我想显示两个图像中的一个。这很好,但我如何在显示图像之间设置停顿。我试过使用:Objective c 如何一个接一个地显示图像,objective-c,Objective C,我目前正在遍历一个列表,根据元素的条件,我想显示两个图像中的一个。这很好,但我如何在显示图像之间设置停顿。我试过使用: for( ... [myView addSubview:myImage] sleep(1) ... ) 每次检查后,由于某种原因,在显示任何图像之前,都会等待函数结束 有人知道这是什么原因以及如何解决吗?这里不能使用sleep(),因为它会阻止更新用户界面的线程 您可以调用另一个方法来设置第二个图像: for( ... [myView ad
for(
...
[myView addSubview:myImage]
sleep(1)
...
)
每次检查后,由于某种原因,在显示任何图像之前,都会等待函数结束
有人知道这是什么原因以及如何解决吗?这里不能使用sleep()
,因为它会阻止更新用户界面的线程
您可以调用另一个方法来设置第二个图像:
for(
...
[myView addSubview:myImage]
// schedule the method.
[myView performSelector:@selector(addSubview:) withObject:mySecondImage afterDelay:1.0f];
...
)
可以将元素的alpha/可见性设置为0.0f/隐藏,并使用具有延迟的动画块来显示视图。通过将持续时间设置为大于0的值,在过程中获得一个奇特的动画;-)
您可以使用“延迟后执行”创建显示图像的功能:
我已经尝试过这个和Marcos解决方案的不同版本,但没有任何东西能让我在显示每个图像之间暂停。定义暂停?我的示例将在1秒后替换
mySecondImage
显示的图像。您可能想增加延迟。对不起,例如,我想在屏幕上创建5个不同的UIImageView
视图,每个视图间隔约1秒。增加下一个performSelector:withObject:afterDelay:
的超时时间,或者使用@Giuseppe Lanza示例中的animationImages
属性。
[UIView animateWithDuration: 0.0
delay: 1.0
options: UIViewAnimationCurveEaseOut
animations: ^{
myView.alpha = 1.0f;
}
completion:^(BOOL finished){}];
-(void)displayImage {
[...get the image...]
[myView addSubview:myImage];
[self performSelector:@selector(displayImage) withObject:nil afterDelay:1.0];
}
NSArray *imageArray = [NSArray arrayWithObjects:image1, image2, imageN, nil];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.animationImages = imageArray;
imageView.animationDuration = [imageArray count]*3;
imageView.animationRepeatCount = 0;
[imageView startAnimating];