如何淡化UIButton

And*_*ref 4 xcode animation view uibutton fadein

我怎样才能在视图中淡入UIButton?

现在我添加它:

    [myView addSubview:myButton];
Run Code Online (Sandbox Code Playgroud)

但如果我想褪色呢?

[UIView animateWithDuration:3.0
delay:0.0
options: UIViewAnimationCurveEaseInOut
animations:^{myButton.alpha = 1.0}
completion:^(BOOL finished){ [myView addSubview:myButton]; }];
Run Code Online (Sandbox Code Playgroud)

谢谢!

Dee*_*olu 9

尝试使用

myButton.alpha = 0.0;
[myView addSubview:myButton];
Run Code Online (Sandbox Code Playgroud)

在动画调用之前.

[UIView animateWithDuration:3.0
                      delay:0.0
                    options: UIViewAnimationCurveEaseInOut
                 animations:^{myButton.alpha = 1.0;}
                 completion:nil];
Run Code Online (Sandbox Code Playgroud)

如果你将其淡入并添加到视图中,则部分淡入将不在视图的范围内(将在屏幕外).所以首先在零alpha处添加它,然后将其淡入.