2

有没有办法动画启用或禁用按钮?我尝试了以下但没有成功。我现在猜测 enabled 属性不能像 opacity 那样动画 - 但我希望我错了。

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0f];
    theButton.enabled = YES;
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];

我不敢相信没有setEnabled:(BOOL)enabled animated:(BOOL)animated方法。

4

5 回答 5

5

这实际上很容易。UIView.transitionWithView可以拍摄任何视图的快照,并从快照交叉融合到视图的新状态。您可以使用该功能为许多更改设置动画,包括enabled.

只需使用 View Controller 的视图作为目标视图,指定TransitionCrossDissolve,然后像往常一样设置动画。

UIView.transitionWithView(self.view,
    duration: 0.5,
    options: UIViewAnimationOptions.TransitionCrossDissolve,
    animations: { () -> Void in
        self.someButton.enabled = !self.someButton.enabled
}, completion:nil)
于 2015-04-03T21:36:46.310 回答
1

动画属性(通过 UIView beginAnimations:context:)是:frame、bounds、center、transform、alpha(来自 Apple 文档)。

所以你必须确定你的动画到底是什么(就颜色/alpha/变换动画而言)并创建手动动画(也许你必须使用 CAAnimation 而不是 UIView beginAnimations:context:)

于 2010-04-11T12:13:24.593 回答
0

您可以将按钮的启用/禁用分解为两个重叠图像之间的不透明度变化,每个图像都处于一种或另一种状态(即使其看起来像淡入/淡出)。在动画完成处理程序中,您可以执行实际的启用/禁用切换。

于 2009-11-18T05:36:30.630 回答
0

这是一个想法:)

在您的动画块中,从视图中删除按钮并再次添加它并禁用状态。你可以在这里指定你想要什么样的动画..

于 2009-11-18T05:36:35.820 回答
0

设置:self.buttonSetEvent.customView.alpha = 0.2;

试试这个

    CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.15];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];

self.buttonSetEvent.customView.alpha = 1;

[UIView setAnimationDelegate:self];
[UIView commitAnimations];
于 2011-02-04T18:51:56.377 回答