2012-04-24 9 views
3

次のコードに問題が有線接続されています。Iphoneのスライドショーとトランジション?

私はこれらのコードを使用して、私はシミュレータ上で実行すると、彼は私には、移行の最初の2つの画像だけを表示します。私はそれを私はアイフォーンで実行する場合、彼は私にちょうど最初の画像を示しています。 また、彼は写真を繰り返さない.-

何が間違っているの?

- (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];  
} 
関連する問題