6

私がやりたいことは、ユーザーがボタンをクリックすると、ボタンが下から上にアニメーションで色で塗りつぶされることです。

色を追加したこれを試しましたが、アニメーション効果は追加されませんでした。

float originalY = btn.frame.origin.y;
float originalH = btn.bounds.size.height;

[UIView animateWithDuration:3.0f
                      delay:1.0f
                    options:UIViewAnimationOptionTransitionFlipFromBottom
                 animations:^{

    btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);
    [btn setBackgroundImage:[UIImage imageNamed:@"Screen Shot 2012-11-07 at 4.22.30 PM.png"] forState:UIControlStateNormal];
    [btn setTitleColor:[[UIColor alloc]initWithRed:38.0/255.0 green:38.0/255.0 blue:38.0/255.0 alpha:1.0] forState:UIControlStateNormal];
} completion:^(BOOL finished) {
}];
4

2 に答える 2

-1

最善の解決策は、UIButton をサブクラス化し、背景画像のアルファ値を 0 から 1 に変更するメソッドを追加することです。

または、drawRect メソッドをオーバーライドして、背景を色で塗りつぶすこともできます。

于 2012-11-08T19:58:51.563 に答える
-2

あなたはおそらくこのようなことをしていると思います.UIlabelを使用してUIButtonでも動作する可能性があります.

#import <QuartzCore/QuartzCore.h>

....

'theLabel.layer.backgroundColor = [UIColor whiteColor].CGColor;

[UIView animateWithDuration:2.0 アニメーション:^{ theLabel.layer.backgroundColor = [UIColor greenColor].CGColor; } 完了:NULL];'`

于 2014-08-12T10:46:07.743 に答える