2012-05-09 35 views
0

我想製作類似動畫的東西。我想在圖像1上的IW1和圖像2上的IW1中更改圖像,然後在圖像1上的IW2上更改圖像,然後在圖像2上更改圖像上的圖像之後,更改圖像在IW3中的image1和下一個image2上,然後在IW4上對image1和image2上的圖像進行更改。依次更改UIImageView中的圖像

不幸的是,當我試圖做到這一點時,我唯一能做的就是同時更改所有UIImageView中的圖像,但我希望按順序執行。

有人會幫忙嗎?

+0

你能顯示一些代碼嗎? – sergio

回答

1

我會做這樣

頭接口

int j; 
int i; 

UIImageView *imgV1; 
UIImageView *imgV2; 
UIImageView *imgV3; 
UIImageView *imgV4; 

UIImage *img1; 
UIImage *img2; 

NSArray *views; 
NSArray *imgs; 

實施

- (void)viewDidLoad{ 
    i=0; 
    j=0; 
    views = [[NSArray alloc] initWithObjects:imgV1, imgV2, imgV3, imgV4, nil]; 
    imgs = [[NSArray alloc] initWithObjects:img1, img2, nil]; 
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(changeImage) userInfo:nil repeats:YES]; 
} 


-(void)changeImage{ 
    UIImageView *imageView = [views objectAtIndex:j]; 
    UIImage *image = [imgs objectAtIndex:i]; 
    imageView.image = image; 
    i++; 
    if(i==2){ 
     i=0; 
     j++; 
     if(j==4) 
      j=0; 
    } 
} 

希望這有助於(我沒有嘗試)

+0

對不起,很晚纔回答。 你的方法非常簡單,它正是我想要的。感謝幫助! – murzynpl

0

調用這個地方

[self performSelector:@selector(changeImage:) withObject:yourImageView afterDelay:1] 

延遲1秒之後會調用這個

-(void)changeImage:(UIImageView *)yourImageView 
{ 
    yourImageView.image = yourImage; 
} 
1
- (void)runSwitchImages 
{ 
    [UIView animateWithDuration:2 delay:2 options:UIViewAnimationCurveEaseInOut animations:^{ 
     //Animate Image Change Here 
    } completion:^(BOOL finished) { 
     //When The Image is done animating it will go here 

    }]; 
} 

您可以使用像這樣做的修改在系列。您可以爲每個圖像創建另一個這些功能,並讓它們串聯。或者將函數更改爲遞歸。

如果你想讓它繼續改變我們的NSTimer來調用函數。