2011-02-24 4 views
0

앱로드시 일련의 이미지를 하나씩 표시하고 싶습니다. 기본적으로 이러한 이미지를 순차적으로로드하여 일종의 애니메이션을 만들고 싶습니다.앱이 iPhone SDK에로드 될 때 일련의 이미지를 표시하는 방법은 무엇입니까?

나는 그것이 가능하다는 것을 알고있다. 나는 그것을하는 많은 응용을 보았다.

이 작업을 어떻게 수행 할 수 있는지 알려주십시오.

감사합니다.

답변

1

UIImageView의 animationImages 속성을 살펴보십시오. NSArray 이미지를이 속성에 할당 할 수 있습니다. 아래는 예제이지만, 저는 이것을 메모리에서 타이핑 할 때 오타가있을 수 있습니다.

-(void)viewDidLoad 
{ 
UIImageView *flower = [[UIImageView alloc] init]; 
flower.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"bloom1.png"],[UIImage imageNamed:@"bloom2.png"], [UIImage imageNamed:@"bloom3.png"], nil]; //add more images as necessary 

flower.animationDuration = 1.00; 
flower.animationRepeatCount = 1; 
[flower startAnimating]; 

[self.view addSubview:flower]; 

[flower release] 
} 
0

예, 이것은 시작 화면 후 화면의 시리즈를 표시하고 응용 프로그램의 첫 번째보기가 나타나기 전에 가능합니다. 당신의 AppDelegate.m 파일에 코드 아래에있는 추가를위한

`- (BOOL) 응용 프로그램 : (UIApplication *) 응용 프로그램의 didFinishLaunchingWithOptions : (NSDictionary와 *) launchOptions {

// create the view that will execute our animation 

[self.window addSubview:firstViewController.view]; 

{ 
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 480)]; 

// load all the frames of our animation 
imageView.animationImages = [NSArray arrayWithObjects: 
          [UIImage imageNamed:@"img1.png"], 
          [UIImage imageNamed:@"img2.png"], 
          [UIImage imageNamed:@"img3.png"], 
          [UIImage imageNamed:@"img4.png"], 
          [UIImage imageNamed:@"img5.png"], 
          nil]; 

imageView.animationDuration = 10.0; 


// repeat the annimation once 
imageView.animationRepeatCount = 1; 
[imageView startAnimating]; 

// add the animation view to the main window 
[window insertSubview:imageView aboveSubview:firstViewController.view]; 
[imageView release]; 

을}

[window setNeedsLayout]; 
[window makeKeyAndVisible]; 
return YES; 

} `

0
-(void)viewDidLoad 
{ 
[super viewDidLoad]; 
animationImageNumber=0; 
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self     
    selector:@selector(startAnimation) userInfo:nil repeats:YES];  
} 

-(void)startAnimation 
{ 
    if (animationImageNumber<9) { 
    animationImageNumber++; 
    } 
    else 
    { 
    animationImageNumber=0; 
    } 
    [self animationImageChange:[NSString stringWithFormat:@"%d",animationImageNumber]]; 
    } 

-(void)animationImageChange:(NSString *)imageName 
{ 
    NSString* imagePath=[[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"]; 
    [backgroundImage setImage:[UIImage imageWithContentsOfFile:imagePath]]; 
    } 
관련 문제