开发者

How Fade in UIButton

开发者 https://www.devze.com 2023-03-09 19:17 出处:网络
how can I fade in a UIButton in a view? now I add it with: [myView addSu开发者_开发百科bview:myButton];

how can I fade in a UIButton in a view?

now I add it with:

    [myView addSu开发者_开发百科bview: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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消