2011-10-14 17 views
10

Bir animasyonun ne zaman biteceğini algılamak için bir yöntem var mı? Animasyon bittiğinde [nav setTitle:navItem]'u aramak istiyorum.iOS: Bir animasyon bittiğinde nasıl algılanır?

Aşağıda, kodumun bir pasajı var. Umarım soru yeterince açıktır, bu yüzden bir çözüm ve tercihen bir örnek alabilirim.

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{ 

if(event.subtype == UIEventSubtypeMotionShake){ 


    NSString *imageUrl = @""; 
    NSString *navItem = @""; 

    int randomNumber = arc4random() % 3; 

    switch (randomNumber) { 
     case 0: 
      imageUrl = @"pic1.png"; 
      navItem = @"txt1"; 
      break; 
     case 1: 
      imageUrl = @"pic2.png"; 
      navItem = @"txt2"; 
      break; 
     case 2: 
      imageUrl = @"pic3.png"; 
      navItem = @"txt3"; 
      break; 
     default: 
      break; 
    } 

    animation.animationImages = [NSArray arrayWithObjects: 

           [UIImage imageNamed:@"pic1.png"], 
           [UIImage imageNamed:@"pic3.png"], 
           [UIImage imageNamed:@"pic2.png"], 
           [UIImage imageNamed:@"pic1.png"], 
           [UIImage imageNamed:@"pic2.png"], 
           [UIImage imageNamed:@"pic3.png"], 
           [UIImage imageNamed:imageUrl], 
           nil]; 

    UIImage *img = [UIImage imageNamed:imageUrl]; 
    [imageview setImage:img]; 

    [animation setAnimationRepeatCount:1]; 
    animation.animationDuration = 1; 
    [animation startAnimating]; 

    [nav setTitle:navItem]; 

} 

} 
+2

Eğer bir cevabı bulursanız, sorununuzu çözerseniz, bunu kabul etmek iyidir ve 2 puan kazanırsınız. – zaph

cevap

4

[animation isAnimating] == NO.

while ([animation isAnimating]) { 
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]]; 
} 
+0

Çok teşekkürler, sadece ihtiyacım olan şey. Sorun çözüldü! :) – thar

+1

@thar: Eğer bu problemi çözdüyse, cevabı "kabul et": http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –

+0

Bu görünmüyor artık çalışmak için: http://stackoverflow.com/questions/3144300/isanimating-return-is-faulty-for-uiimageview-for-iphone – Nuthinking

10

Sen setAnimationDidStopSelector temsilci kullanabilirsiniz:

bunu bitmesini bekleyin ancak UI engellemez istiyorsanız

. http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CAAnimation_class/Introduction/Introduction.html

sadece animasyon sen anlattın süreyi tamamlamak varsayar
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 


- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context { 
    /*Do stuff*/ 
} 
+2

Bu animasyonImages türü animasyon için çalışıyor olup olmadığını bilmiyorum. Sadece [UIView beginAnimations: context:] kullanarak animasyonlarla çalışır. – morningstar

+3

Animasyon tipi animasyon animasyonu için çalışmaz. – Dustin

-2
[self performSelector:@selector(animationFinished) withObject:nil afterDelay:1.0]; 

-(void)animationFinished { 
    // do stuff 
} 


.

İlgili konular