2012-03-15 100 views
4

我想在使用淡入淡出效果的imageview中製作幻燈片。在ImageView中淡入淡出幻燈片。 xCode 4.2

到目前爲止,香港專業教育學院做到了這一點:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    animationView = [[UIImageView alloc] initWithFrame:self.view.frame]; 
    animationView.animationImages = [NSArray arrayWithObjects: 
            [UIImage imageNamed:@"photo1.jpg"], 
            [UIImage imageNamed:@"photo2.jpg"], 
            [UIImage imageNamed:@"photo3.jpg"], nil]; 

    animationView.animationDuration = 5; 
    animationView.animationRepeatCount = 0; 
    [animationView startAnimating]; 
    [self.view addSubview:animationView]; 
} 

圖像確實出現一前一後,在5秒的延遲,我現在想要的是讓他們淡入和淡出每次圖像出現,對此有什麼建議?

在此先感謝您的幫助

+0

沒有人知道這個答案嗎?我一直在努力尋找解決方案,我唯一想出來的東西(這不是很好,但有點作品)是通過做出一些空白,並用選擇器調用它們,我設法使圖像看起來像淡入淡出一樣消失(通過改變阿爾法),但那不能很好地工作,它給你一種假的褪色感 – Nick 2012-03-22 00:21:20

回答

6

我正在嘗試做類似的事情。我所做的就是設置一個計時器,該計時器在UIImageView上調用UIViewtransitionWithView,該計時器在我的幻燈片照片陣列中遞增。

- (void)viewDidLoad{ 
[super viewDidLoad]; 
self.welcomePhotos = [NSArray arrayWithObjects:@"welcome_1.png",@"welcome_2.png", @"welcome_3.png", nil]; 
self.imageView1.image = [UIImage imageNamed:[self.welcomePhotos objectAtIndex:0]]; 
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES]; 
} 


-(void)transitionPhotos{ 

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

如何在'.h'中聲明'photoCount'? – 2013-04-14 22:52:11

+0

可以在@implementation下將photoCount聲明爲static int photoCount; – EHarpham 2013-11-23 14:24:04

相關問題