iPhoneで、下記100個の画像ファイルを0.1秒おきに差し替えるやり方です。
image_00000.jpg
image_00001.jpg
...
image_00099.jpg
実装方法は、NSTimerを利用して0.1秒ごとに、
UIImageViewのimageを差し替える感じです。
主要クラスのリファレンスは次の通りです。
【NSTimer】
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html
【UIImageView】
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html
【UIImage】
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html
最終的なコードは下記のようになりました。
--------【Objective-C】--------
#import "Test02ViewController.h"
@implementation Test02ViewController
@synthesize imageView;
NSTimer *timer = nil;
int sequence = 0;
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"start");
[NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(onTimer:)
userInfo:nil
repeats:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
- (void)onTimer:(NSTimer *)timer {
NSString *imageName = [NSString stringWithFormat: @"image_%05d", sequence];
NSString *imagePath = [
[NSBundle mainBundle] pathForResource:imageName
ofType:@"jpg"
];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
imageView.image = image;
[image release];
sequence++;
if (sequence > 100 && [timer isValid]) {
[timer invalidate];
NSLog(@"stop");
}
}
@end
--------
メモリ管理系は、結構、理解してきたなー…
--------
http://www.suz-lab.com

0 コメント:
コメントを投稿