2012-04-24 9 views
3

다음 코드와 관련된 문제점이 있습니다.아이폰의 슬라이드 쇼와 전환?

이 코드를 사용하여 시뮬레이터에서 실행하면 그는 전환과 함께 배열의 처음 두 그림 만 보여줍니다. 아이폰에서 실행하면 그는 첫 번째 사진을 보여줍니다. 그는 또한 사진을 반복하지 않습니다 .-

내가 뭘 잘못 했니?

- (void)viewDidLoad{ 
    [super viewDidLoad]; 

    welcomePhoto = [NSArray arrayWithObjects:@"Bild.jpeg",@"Bild1.jpeg", @"Bild2.png", nil]; 
    imageView.image = [UIImage imageNamed:[welcomePhoto objectAtIndex:0]]; 
    [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES]; 
} 


-(void)transitionPhotos{ 
    int photoCount; 
    if (photoCount < [welcomePhoto count] - 1){ 
     photoCount ++; 
    }else{ 
     photoCount = 0; 
    } 
    [UIView transitionWithView:self.imageView 
         duration:2.0 
         options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^{ imageView.image = [UIImage imageNamed:[welcomePhoto objectAtIndex:photoCount]]; } 
        completion:NULL];  
} 
+0

당신이 당신의 코드를 단계별로 디버거를 사용하여 시도 해 봤나이 코드를 시도? – Stefan

답변

3

viewDidLoad에 추가하십시오.

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 90, 100, 100)]; 
[self.view addSubview:animatedImageView]; 
animatedImageView.animationImages = [NSArray arrayWithObjects:  
            [UIImage imageNamed:@"bild.png"], 
            [UIImage imageNamed:@"bild.png"], 
            [UIImage imageNamed:@"bild.png"], nil]; //etc 
animatedImageView.animationDuration = 3.0f * [animatedImageView.animationImages count]; 
animatedImageView.animationRepeatCount = 0; 
[animatedImageView startAnimating]; 
[self.view addSubview: animatedImageView]; 
+0

thx 코드가 작동 중입니다. 코드에 전환을 추가하는 방법은 무엇입니까? 내가 한 것처럼 다른 방법이 있니? – Bashud

1

발견했습니다. transitionPhotos에서 photoCount 초기화를 건너 뜁니다. iVar 또는 속성으로 지정하십시오.

+0

Ahhhhhh thx. 그건 내 잘못 이었어 – Bashud

+0

varsågod! 나는 짐작한다. – TompaLompa

2

NSArray *imagesArray; 
int photoCount; 
UIImageView *imageView; 
-(void)setupImageView{ 
    photoCount = 0; 
    [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"imgA.png"] ,[UIImage imageNamed:@"imgB.png"] ,[UIImage imageNamed:@"imgC.png"] ,[UIImage imageNamed:@"imgD.png"] ,[UIImage imageNamed:@"imgE.png"] , nil];   imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)]; 
    imageView.image = [imagesArray objectAtIndex:photoCount]; 
    [self.view addSubview:imageView]; 
    [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES]; 

} 

-(void)transitionPhotos{ 


if (photoCount < [imagesArray count] - 1){ 
    photoCount ++; 
}else{ 
    photoCount = 0; 
} 
[UIView transitionWithView:self.imageView1 
        duration:2.0 
        options:UIViewAnimationOptionTransitionCrossDissolve 
       animations:^{ imageView.image = [imagesArray objectAtIndex:photoCount]; } 
       completion:NULL];  
} 
관련 문제