2014-03-01 87 views
-1

夥計們我需要知道如何在遊戲加載後如何顯示下降7秒的圖像?延時下降圖像

這是我當前的代碼:

.h文件

IBOutlet UIImageView *CloudDrop; 
NSTimer *timer; 

-(void)CloudDropCode; 

.m文件

-(void)CloudDropCode{ 
    // Drop Cloud Images Animation 
    CloudDrop.animationImages = [NSArray arrayWithObjects: 
          [UIImage imageNamed:@"CloudDrop2.png"], 
          [UIImage imageNamed:@"CloudDrop.png"], 
          [UIImage imageNamed:@"CloudDrop2.png"], 
          [UIImage imageNamed:@"CloudDrop.png"], 
          [UIImage imageNamed:@"CloudDrop2.png"], 
          [UIImage imageNamed:@"CloudDrop.png"], 
          [UIImage imageNamed:@"CloudDrop2.png"], 
          [UIImage imageNamed:@"CloudDrop.png"],nil]; 

    [CloudDrop setAnimationRepeatCount:1]; 
    CloudDrop.animationDuration = 0.1; 
    [CloudDrop startAnimating]; 

    // Drop Cloud Ramdom Position 
    CloudDrop.center = CGPointMake(CloudDrop.center.x, CloudDrop.center.y +2); 
    if (CloudDrop.center.y > 590){ 
     ramdomPosition = arc4random() %266; 
     ramdomPosition = ramdomPosition +54; 

     CloudDrop.center = CGPointMake(ramdomPosition, -40); 
     dropCloudUsed = NO; 

    // Time to Drop Cloud Down Again 
     [[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:7.0]]; 

     CloudDrop.hidden = NO; 
    } 
} 

這在viewDidLoad

- (void)viewDidLoad 
    timer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(CloudDropCode)userInfo:nil repeats:YES]; 

現在,遊戲加載時圖像會下降。我試圖在遊戲加載10秒後降低圖像。任何想法或建議?由於

+0

歡迎來到SO。請注意,本網站不是「給我代碼」網站。這個網站是爲了幫助那些已經完成他們的研究的人,嘗試了一些東西,但需要一些幫助來解決一些問題。請點擊上面的幫助鏈接,閱讀如何提出正確的問題。 – rmaddy

+0

如果您嘗試過某些功能並且無法正常工作,請使用相關代碼更新您的問題。詳細描述你有什麼問題。 – rmaddy

回答

0

定義變量:

CloudDrop.animationImages = [NSArray arrayWithObjects: 
         [UIImage imageNamed:@"CloudDrop2.png"], 
         [UIImage imageNamed:@"CloudDrop.png"],nil]; 

NSUInteger currentIndex = 0; 

重複下一個方法7倍

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ 
    //Update there. get next image by index and realize animation 
} completion:^(BOOL finished) { 
    if (currentIndex == 0) 
     currentIndex++; 
    else 
     currentIndex = 0; 
}]; 

實現替代函數調用它的完成自己。