2016-04-13 8 views
0

Ich habe einen Fehler in meinem Code, die ich beheben können nicht .. hier ist mein Code .. es innerhalb der ersten ist if-Anweisung, wo current_region++ auftritt ... bitte helft mir, dankeVariable ist nicht übertragbar (fehlende __block Typspezifizierer)

-(void)planetRotation:(UIView *)planet average:(float)time1 perihelion:(float)time2 aphelion:(float)time3 region:(int) current_region 
{ 
    current_region = 0; 

    [planet.layer removeAllAnimations]; 

    if (current_region == 0 || current_region == 2) 
    { 
     [UIView animateWithDuration:time1 delay:0.0 options: UIViewAnimationOptionTransitionNone 
     animations: ^{ CABasicAnimation* rotationAnimation; 
         rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
         rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * time1 * 1 ];//multiply more to add speed 
         rotationAnimation.duration = time1/4; 
         rotationAnimation.cumulative = YES; 
         rotationAnimation.repeatCount = HUGE_VALF; 
      [planet.layer addAnimation:rotationAnimation forKey:@"orbit"];} completion:^(BOOL finished){current_region++; }]; 
    } 
    else if(current_region == 1) 
    { 
     [UIView animateWithDuration:time2 delay:0.0 options: UIViewAnimationOptionTransitionNone 
     animations:^{ CABasicAnimation* rotationAnimation; 
         rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
         rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * time2 * 1 ];//multiply more to add speed 
         rotationAnimation.duration = 15; 
         rotationAnimation.cumulative = YES; 
         rotationAnimation.repeatCount = HUGE_VALF; 
      [planet.layer addAnimation:rotationAnimation forKey:@"orbit"];} completion:^(BOOL finished){ }]; 
    } 
    else if(current_region == 3) 
    { 
     [UIView animateWithDuration:time3 delay:0.0 options: UIViewAnimationOptionTransitionNone 
      animations:^{ CABasicAnimation* rotationAnimation; 
         rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
         rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * time3 * 1 ];//multiply more to add speed 
         rotationAnimation.duration = 15; 
         rotationAnimation.cumulative = YES; 
         rotationAnimation.repeatCount = HUGE_VALF; 
      [planet.layer addAnimation:rotationAnimation forKey:@"orbit"];} completion:^(BOOL finished){ }]; 
    } 

Antwort

0

Wenn Sie Ihre current_region Variable deklarieren Sie die Deklaration wie folgt ändern müssen:

__block int current_region = 0; 

Apple says:

__Sperren von Variablen im Speicher, der zwischen dem lexikalischen Gültigkeitsbereich der Variablen und allen deklarierten Blöcken und Blockkopien oder innerhalb des lexikalischen Gültigkeitsbereichs der Variablen aufgeteilt ist. Somit wird der Speicher die Zerstörung des Stapelrahmens überleben, wenn Kopien der Blöcke, die innerhalb des Rahmens deklariert sind, über das Ende des Rahmens hinaus existieren (für beispielsweise, indem sie irgendwo für die spätere Ausführung in eine Warteschlange eingereiht werden). Mehrere Blöcke in einem gegebenen lexikalischen Bereich können gleichzeitig eine gemeinsame Variable verwenden.

Verwandte Themen