2010-09-27 20 views

cevap

20

Sen (ben animasyon için repeatCount tesiste şamandıra olduğu yanlış hatırlamıyorsam) değerini yüzen için HUGE_VAL kullanabilirsiniz. 360 derece (2 * M_PI radyan) üzerinde rotasyonlar çünkü eğer doğru sadece UIView animasyonlar kullanarak dönme bu tür oluştururken hatırlıyorum Eğer

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
animation.fromValue = [NSNumber numberWithFloat:0.0f]; 
animation.toValue = [NSNumber numberWithFloat: 2*M_PI]; 
animation.duration = 3.0f; 
animation.repeatCount = HUGE_VAL; 
[rotView.layer addAnimation:animation forKey:@"MyAnimation"]; 

imkansızdır: Kurulum animasyon için

Eğer +animationWithKeyPath: yöntemi kullanarak CAAnimation nesnesi oluşturabilir hiç dönüş olmaksızın optimize edilmiştir.

+0

iyi geliyor! ancak görüntüyü tam 390 derece döndürmek ve yuvarlanmaya devam etmek için animasyonu nasıl kurabilirim? – openfrog

+0

@openfrog Bu doğru cevaptır. Görünümü, görünümü katmanını temel bir animasyonla açıkça döndürerek döndürürsünüz. Vladimir'in önerdiği şeyi yaparsanız, "yuvarlanmaya devam edecek". –

0

bahse girerim ki:

-(void)animationDidStopSelector:... { 
    [UIView beginAnimations:nil context:NULL]; 
    // you can change next 2 settings to setAnimationRepeatCount and set it to CGFLOAT_MAX 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStopSelector:...)]; 
    [UIView setAnimationDuration:... 

    [view setTransform: CGAffineTransformRotate(CGAffineTransformIdentity, 6.28318531)]; 

    [UIView commitAnimations]; 
} 

//start rotation 
[self animationDidStopSelector:...]; 

ok iyi bahis:

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationRepeatCount: CGFLOAT_MAX]; 
[UIView setAnimationDuration:2.0f]; 

[view setTransform: CGAffineTransformMakeRotation(6.28318531)]; 

[UIView commitAnimations]; 
2

o çekirdek animasyon kullanmaz ama en azından sonsuza gerçekten çalıştığı için bu benim çözüm biraz hacky olduğunu ve kurulum çoklu animasyon adımlara gerektirmez.

... 
// runs at 25 fps 
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:1.0/25 
          target:self 
          selector:@selector(rotate) 
          userInfo:nil 
          repeats:YES]; 
[timer fire]; 
... 

- (void)rotate { 
    static int rotation = 0; 

    // assuming one whole rotation per second 
    rotation += 360.0/25.0; 
    if (rotation > 360.0) { 
     rotation -= 360.0; 
    } 
    animatedView.transform = CGAffineTransformMakeRotation(rotation * M_PI/180.0); 
} 
İlgili konular