ボタンのタイトルをアニメーションで変更したい。たとえば、ボタンのタイトルは「one」です。そのボタンをクリックすると、「one」がフェードアウトしてから「NewTitle」がフェードインします。
			
			2006 次
		
2 に答える
            0        
        
		
2 つのボタンを作成するのは良い考えではなかったので、質問のコードをテストするための簡単なプロジェクトを作成しました。
viewcontroller.h
   #import <UIKit/UIKit.h>
    @interface ViewController : UIViewController{
        IBOutlet UIButton *myButton;
    }
    @property(nonatomic,strong) IBOutlet UIButton *myButton;
    -(IBAction)animateFadeOutButtonTitle:(id)sender;
    -(void)animateFadeInButtonTitle;
    @end
viewcontroller.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize myButton=_myButton;
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [_myButton setTitle:@"One" forState:UIControlStateNormal];
}
-(IBAction)animateFadeOutButtonTitle:(id)sender
{
    [UIView animateWithDuration:0.25 animations:^{_myButton.titleLabel.alpha = 0.0;}];
    [self performSelector:@selector(animateFadeInButtonTitle) withObject:self afterDelay:1.0];
}
-(void)animateFadeInButtonTitle;
{
    [_myButton setTitle:@"New Title" forState:UIControlStateNormal];
    [UIView animateWithDuration:2.0
                          delay:0.0
                        options: UIViewAnimationCurveEaseInOut
                     animations:^{_myButton.titleLabel.alpha = 1.0;}
                     completion:nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
    于 2012-12-13T14:44:24.590   に答える