xcode IOS:在 UIImage 中设置 alpha

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7488845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:59:09  来源:igfitidea点击:

IOS: set alpha in a UIImage

iosxcodeuiimagealpha

提问by cyclingIsBetter

I have an UIImage and I want to set its alpha at 0.00 after 3 seconds... In my UIImage there is a picture that I want to immediately see when I go in a view, but after 3 second it must disappear.

我有一个 UIImage,我想在 3 秒后将它的 alpha 设置为 0.00...在我的 UIImage 中有一张我想在进入视图时立即看到的图片,但在 3 秒后它必须消失。

回答by roman

Easy as that using core animation

使用核心动画就这么简单

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0f];
imageView.alpha = 0.0f;
[UIView commitAnimations];

if you dont want to slowly fade within 3 seconds, you can use

如果你不想在 3 秒内慢慢淡出,你可以使用

[UIView setAnimationDelay:3];

and reduce the animation duraction to 0.5f or something. i think using a short fade out time feels better than just simply set hide to YES

并将动画持续时间减少到 0.5f 左右。我认为使用较短的淡出时间比简单地将隐藏设置为 YES 感觉更好

回答by Peter DeWeese

This will make it fade out within three seconds. Call from viewDidLoad:

这将使其在三秒钟内淡出。从 viewDidLoad 调用:

[UIView animateWithDuration:3.0 animations:^{myImage.alpha = 0; }];

Or if you want the animation to start at 2.5 seconds and last half a second, you could put that into a method (changing 3.0 to 0.5) and then call:

或者,如果您希望动画从 2.5 秒开始并持续半秒,您可以将其放入一个方法中(将 3.0 更改为 0.5),然后调用:

[NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(hideMyImage) userInfo:nil repeats:no];

回答by adpalumbo

Are you showing your UIImagein a UIImageView?

你是在展示你UIImageUIImageView吗?

If so, just set the hiddenproperty on that image view to YES and the image view (with its image) will disappear.

如果是这样,只需hidden将该图像视图上的属性设置为 YES,图像视图(及其图像)就会消失。

回答by bdparrish

You can always remove the sub-child view from the parent.

您始终可以从父视图中删除子子视图。

[imageView removeFromSuperview];

you can always add it later with

你以后可以随时添加它

[self.view addSubview:imageView];