0

我目前正在遍历一个列表,并根据我想显示两个图像之一的元素的条件。这工作正常,但我如何在显示图像之间暂停。我试过使用:

for(
   ...
   [myView addSubview:myImage]
   sleep(1)
   ...
)

每次检查之后,但由于某种原因,这会在显示任何图像之前等待函数结束。

有谁知道这是什么原因以及如何解决它?

4

4 回答 4

1
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];
于 2012-10-19T10:07:16.973 回答
0

您可以创建一个函数来显示使用“延迟后执行”的图像:

-(void)displayImage {
    [...get the image...]

    [myView addSubview:myImage];

    [self performSelector:@selector(displayImage) withObject:nil afterDelay:1.0];
}
于 2012-10-19T08:40:44.030 回答
0

您不能sleep()在此处使用,因为它会阻塞更新您 UI 的线程。

你可以做的是调用一个不同的方法来设置第二个图像:

for(
   ...
   [myView addSubview:myImage]
   // schedule the method.
   [myView performSelector:@selector(addSubview:) withObject:mySecondImage afterDelay:1.0f];
   ...
)
于 2012-10-19T08:40:01.030 回答
0

您可以将元素的 alpha/visibility 设置为 0.0f/hidden 并使用具有延迟的动画块来显示视图。通过将持续时间设置为大于 0 的值,在此过程中获得精美的动画;-)

[UIView animateWithDuration: 0.0
                      delay: 1.0
                    options: UIViewAnimationCurveEaseOut
                 animations: ^{
                         myView.alpha = 1.0f;
                     }
                 completion:^(BOOL finished){}];
于 2012-10-19T08:40:03.240 回答