xcode UIButton 如何淡入淡出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6178531/
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
How Fade in UIButton
提问by Andref
how can I fade in a UIButton in a view?
如何在视图中淡入 UIButton?
now I add it with:
现在我添加它:
[myView addSubview:myButton];
but if I want to fade it?
但如果我想淡化它呢?
[UIView animateWithDuration:3.0
delay:0.0
options: UIViewAnimationCurveEaseInOut
animations:^{myButton.alpha = 1.0}
completion:^(BOOL finished){ [myView addSubview:myButton]; }];
Thanks!
谢谢!
回答by Deepak Danduprolu
Try using
尝试使用
myButton.alpha = 0.0;
[myView addSubview:myButton];
prior to the animation call.
在动画调用之前。
[UIView animateWithDuration:3.0
delay:0.0
options: UIViewAnimationCurveEaseInOut
animations:^{myButton.alpha = 1.0;}
completion:nil];
If you fade it in and add to view, the fading in part will not be within the bounds of the view (will be offscreen). So add it first at zero alpha and then fade it in.
如果您将其淡入并添加到视图中,则淡入部分将不在视图范围内(将在屏幕外)。因此,首先在零 alpha 处添加它,然后将其淡入。
回答by Mark
You should first add the view as a subview like you did with
您应该首先将视图添加为子视图,就像您所做的那样
[myView addsubview:myButton];
Give it an alpha of 0.0 when you add it to your view. After that you should animate your button to an alpha value of 1.0
将其添加到视图时,将其 alpha 设置为 0.0。之后,您应该将按钮设置为 alpha 值 1.0