动画UIButtons

时间:2010-10-01 10:58:48

标签: iphone uiview uibutton

我想要制作一些动画按钮。

我已经查看并尝试了animateWithDuration方法,但这似乎适用于Views,我无法让我的实现工作。

此方法也适用于动画按钮吗?如果不能怎么做呢?

EDIT 我有以下代码

-(void) animate:(UIButton*) b withMonster: (int) monster withState: (int) state andLastState:(int) last_state {
if (state < last_state) {
    float duration = 1.0 / 10;
    __block int stateTemp = state;
    [b animateWithDuration: duration
                animations: ^{ [UIImage imageNamed:[NSString stringWithFormat:@"m%d.a000%d.png", monster, state]]; }
                completion: ^{ [self animate: A1 withMonster: monster withState: stateTemp++ andLastState: last_state];; }];


}

我称之为

[self animate: A1 withMonster: monsterDecider withState: 1 andLastState: 5];

当此代码执行应用程序崩溃时。

在两个调用中调用self都是正确的(自己是ViewController)。

由于

1 个答案:

答案 0 :(得分:1)

你可以动画按钮,是的。在动画块中,您需要更改一些按钮参数,如下所示:

[UIView animateWithDuration:animTime
                 animations:^{button.frame = newFrame;}];

查看代码,您可能希望将button.imageView.image属性设置为新图像(您的代码当前加载新图像但不将其设置到按钮上)。

但是,UIImageView对象实际上支持在多个图像之间进行切换,而无需使用UIView animateWithduration:...方法。

您可能想要设置以下属性:

button.imageView.animationImages
button.imageView.animationDuration
button.imageView.animationRepeatCount

然后致电

[button.imageView startAnimating];

并且UIImageView将为您完成所有动画。 查看UIImageView上的文档: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImageView_Class/Reference/Reference.html