2014-06-11 129 views
2

我想倒計時圖像時,視圖將load.for爲此我推遲所有功能時,視圖將load.i鑑於負荷做倒計時圖像時負載視圖

- (void)viewDidLoad 
{ 
//-=-=-=-=-=-=-=-=-=-=-=-=-=Count Down Numbers animation-=-=-=-=-=-=-=-=-=- 
    NumImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"03.png"],   [UIImage imageNamed:@"02.png"],[UIImage imageNamed:@"01.png"], nil]; 
    NumImageView.animationDuration =4; 

    [numView addSubview:NumImageView]; 

    [NumImageView startAnimating]; 
.......//remaining code 

} 

這裏我在numView上刪除NumImageView是UIImageView

但沒有獲得所有圖像。3和1動畫顯示剩餘的2張圖像。其實這是正確的過程或使用NSThread是正確的過程,但我現在不怎麼使用NSThread

+0

我不完全聽懂你的問題,但是我可以告訴你現在你不想在不同的線程上做UI的東西,所有的UI動畫和改變應該發生在主線程 – Fonix

+0

好吧,但如何動畫像倒計時的圖像。 – RameshIos

回答

0

您還可以與移動到下一個動畫塊實現這一目標當這種方法達到像完成動畫:

- (void)animateCountDown 
{ 
    //first add numImageView 
    [numView addSubview:numImageView]; 
    //add first image 
    numImageView.image = [UIImage imageNamed:@"03.png"]; 
    [UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^ 
    { 
     numImageView.image = [UIImage imageNamed:@"02.png"]; 
    } 
        completion:^(BOOL finished) 
        { 
         [UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^ 
          { 
           numImageView.image = [UIImage imageNamed:@"01.png"]; 
          } 
              completion:^(BOOL finished) 
              { 
               //start whatever after countdown 
              }]; 
        }]; 
} 

然後在你的viewDidLoad稱此像這樣[self animateCountDown];

另一種方法是使用NSTimer。我做了一個例子,所以你可以看到如何使用這個你認爲合適的。在這個例子中NSTimer呼籲其減小,設置正確UIImageUIImageViewcount integercountMethod,該countMethod還檢查count integer變爲低於1,因此可以invalidateNSTimer,你有一個地方調用一個方法來啓動其餘的應用程序。

聽起來很多參加,但看這張截圖,一切都清楚:

NSTimerexample

+0

截圖是完美的.....謝謝你 – RameshIos

0

你可能想要做這樣的事情,我不知道你的實現細節,但是我相信你自己看着辦吧

//add all images into an array with 
NSArray *NumImageView = @{img1, img2, img3, img4}; //these are UIImageViews that you have made previously 

for(int i = 0; i < NumImageView.count; i++){ 
    [numView addSubview:NumImageView[i]]; //add all images 
    NumImageView[i].hidden = true; //make them hidden initially 
} 

for(int i = 0; i < NumImageView.count; i++){ 

    [UIView animateWithDuration:1.0 delay:i*1.0 options:UIViewAnimationOptionCurveLinear animations:^{ 
     NumImageView[i].hidden = false; //unhide when it starts aniamting 

     //animate image coming in 

    } completion:^(BOOL finished) { 
     UIImageView *image = NumImageView[i]; 
     [image removeFromSuperView]; //remove current number 
    }]; 
} 
+0

這裏你不添加圖像到imageView添加到數組並添加到查看....但.hidden和removeFromSuperView屬性未創建錯誤發生 – RameshIos

+0

可能需要將數組元素轉換回適當的類型,生病進行編輯。 img1,img2等,應該是UIImageViews或任何你想要的類型 – Fonix

0

試試這個

-(void)viewdidload 
{ 
[NSThread detachNewThreadSelector:@selector(animateImages) toTarget:self withObject:nil] 
} 

-(void)animateImages 
{ 
//-=-=-=-=-=-=-=-=-=-=-=-=-=Count Down Numbers animation-=-=-=-=-=-=-=-=-=- 
    NumImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"03.png"],   [UIImage imageNamed:@"02.png"],[UIImage imageNamed:@"01.png"], nil]; 
    NumImageView.animationDuration =4; 

    // repeat the annimation forever 
    NumImageView.animationRepeatCount = 1; 
    [NumImageView startAnimating]; 
    [numView addSubview:NumImageView]; 


.......//remaining code 
} 
+0

謝謝你的工作....但repeatCount 1只爲 – RameshIos

+0

for animationRepeatCount = 0沒用? – Bhoomi

+0

3,2,1動畫repeat.when採取計數1它將顯示動畫僅1時間 – RameshIos