UIImageView 淡出 [英] UIImageView fade out
问题描述
在我的主故事板中,我有一个带有隐藏 UIImageView
的 UIViewController
.我在一个线程中读到要淡出图像的线程,我可以使用以下代码.我想知道如何将我用 IBAction
创建的 UIImageView
绑定起来.
In my main storyboard I have a UIViewController
with a hidden UIImageView
. I read in a thread that to fade an image out I could use the following code. I was wondering how to tie the UIImageView
I created with an IBAction
.
-(IBAction)popupImage
{
_imageView.hidden = NO;
_imageView.alpha = 1.0f;
// Then fades it away after 2 seconds (the cross-fade animation will take 0.5s)
[UIView animateWithDuration:0.5 delay:2.0 options:0 animations:^{
// Animate the alpha value of your imageView from 1.0 to 0.0 here
_imageView.alpha = 0.0f;
} completion:^(BOOL finished) {
// Once the animation is completed and the alpha has gone to 0.0, hide the view for good
_imageView.hidden = YES;
}];
}
我是否创建了一个 @property(强,非原子)IBOutlet UIImageView *imageView;
连接到图像?
Do I create a @property (strong, nonatomic) IBOutlet UIImageView *imageView;
connected to the image?
推荐答案
打开辅助编辑器
并按住 ctrl 键将 UIImageView
拖到文件顶部以创建一个名为 imageView
的 IBOutlet.您可以通过以下方式之一调用(调用)您的方法:
and ctrl-drag form the UIImageView
to the top of your file to make an IBOutlet called imageView
. You can invoke (call) your method in one of these ways:
- 如果您想在有人单击按钮时使图像淡化,请按住 ctrl 从 UIButton 拖动到
popupImage
方法以创建IBAction
. - 如果您想以编程方式淡化图像,只需在您希望淡化开始的代码中的任何位置执行
[self popupImage]
(例如,在viewDidLoad
中).在这种情况下,您不需要方法的IBAction
部分,只需调用它- (void)popupImage
.
- If you want to fade the image when someone clicks a button, ctrl-drag from a UIButton to the
popupImage
method to make anIBAction
. - If you want to fade the image programatically, just do
[self popupImage]
from wherever in your code you want the fade to begin (inviewDidLoad
, for example). In this case, you don't need theIBAction
part of your method, and can just call it- (void)popupImage
.
因为您想从一开始就显示您的图像,所以不应将其设置为隐藏.
Since you want to show your image from the beginning, you should not have it set to hidden.
这篇关于UIImageView 淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!