How Fade in UIButton

戏子无情 提交于 2019-12-12 11:35:30

问题


how can I fade in a UIButton in a view?

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!


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6178531/how-fade-in-uibutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!