我有一张UIImage图片,我想在3秒后将它的透明度设置为0.00... 在我的UIImage中,有一张图片,我希望当我进入一个视图时立即看到它,但是在3秒后它必须消失。
使用核心动画就像这样容易
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0f];
imageView.alpha = 0.0f;
[UIView commitAnimations];
如果你不想在三秒内逐渐消失,可以使用:
[UIView setAnimationDelay:3];
将动画持续时间减少到0.5f或其他值。我认为使用短暂的淡出时间比仅仅设置隐藏为YES感觉更好。
这将使其在三秒内淡出。从viewDidLoad调用:
[UIView animateWithDuration:3.0 animations:^{myImage.alpha = 0; }];
如果您希望动画从2.5秒开始,持续半秒钟,您可以把这个方法放入其中(将3.0更改为0.5),然后调用:
[NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(hideMyImage) userInfo:nil repeats:no];
您可以随时从父视图中移除子视图。
[imageView removeFromSuperview];
你随时都可以使用
添加它。[self.view addSubview:imageView];