【发布时间】:2011-05-23 20:39:38
【问题描述】:
我有一个执行一些任务的线程。
最后我想运行一个选择器来隐藏带有动画的图像。
[self performSelectorOnMainThread:@selector(finishUpdate) withObject:nil waitUntilDone:YES];
我将持续时间设置为 10 秒:
- (void) finishUpdate {
UIImageView *myImage = (UIImageView *)[self.view viewWithTag:788];
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:10.0f];
myImage.frame = CGRectMake(0, 200, 320, 80);
myImage.alpha = 0.0f;
[UIView commitAnimations];
}
但它立即消失,线程立即继续。
你知道如何让我的线程等待或如何显示这个简单的动画吗?
【问题讨论】:
-
UIGraphicsGetCurrentContext()通常仅在您的drawRect:方法中返回有效上下文。但这不重要,因为作为context传递给beginAnimations:context:方法的值是供您自己使用的,而不是系统的。 -
@Kristopher:我在线程的开头使用了相同的方法 - 显示图像并且它按预期工作。
-
我的意思是你不需要打电话给
UIGraphicsGetCurrentContext()。您可以将nil作为context参数传递给beginAnimations:context:,这没有任何区别。但这与它为什么不起作用无关。 -
您是否曾经将图像的
hidden属性设置为true?如果是这样,它会立即消失,不管任何动画正在发生。 -
@Kristopher:我只使用 alpha 属性。
标签: multithreading xcode animation