ページ

2011年6月27日月曜日

Xcode : iPhoneでanimation その2 NSArrayを使った方法





animation_with_NSArrayViewController.h

#import 

@interface animation_with_NSArrayViewController : UIViewController {

 IBOutlet UIImageView *image;
 IBOutlet UIButton *button;
}

-(IBAction)spinImage;

@end


animation_with_NSArrayViewController.m

#import "animation_with_NSArrayViewController.h"

@implementation animation_with_NSArrayViewController

-(IBAction)spinImage{
 
 if(image.isAnimating){
  [image stopAnimating];
  [button setTitle:@"Start" forState:UIControlStateNormal];
 }else {
  [image startAnimating];
  [button setTitle:@"Stop" forState:UIControlStateNormal];
 }

}

- (void)viewDidLoad {
 
 NSArray *imageArray;
 imageArray = [[ NSArray alloc] initWithObjects:
      [UIImage imageNamed:@"sonic1.png"],
      [UIImage imageNamed:@"sonic2.png"],
      [UIImage imageNamed:@"sonic3.png"],
      [UIImage imageNamed:@"sonic4.png"],
      [UIImage imageNamed:@"sonic5.png"],
      [UIImage imageNamed:@"sonic6.png"],
      [UIImage imageNamed:@"sonic7.png"],
      [UIImage imageNamed:@"sonic8.png"],
      [UIImage imageNamed:@"sonic9.png"],
      [UIImage imageNamed:@"sonic10.png"],
      [UIImage imageNamed:@"sonic11.png"],
      [UIImage imageNamed:@"sonic12.png"],
      [UIImage imageNamed:@"sonic13.png"],
      [UIImage imageNamed:@"sonic14.png"],
      [UIImage imageNamed:@"sonic15.png"],
      [UIImage imageNamed:@"sonic16.png"],
      [UIImage imageNamed:@"sonic17.png"],
      [UIImage imageNamed:@"sonic18.png"],
      [UIImage imageNamed:@"sonic19.png"],
      [UIImage imageNamed:@"sonic20.png"],
      [UIImage imageNamed:@"sonic21.png"],
      [UIImage imageNamed:@"sonic22.png"],
      [UIImage imageNamed:@"sonic23.png"],
      [UIImage imageNamed:@"sonic24.png"],
      [UIImage imageNamed:@"sonic25.png"], nil];
 
 image.animationImages = imageArray;
 image.animationDuration = 0.4;
 
 [imageArray release];
 
    [super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
 
 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

0 件のコメント:

コメントを投稿