1

애니메이션에 문제가 있습니다. 여기 내가하려는 일이 있습니다. 먼저 나는 몇 가지가 사라지고, 예를for 루프 내에서 UIVIEW의 체인 애니메이션

label1.frame = CGRectMake(xBoard, 5, textWidth, term1Label.frame.size.height); 
    xBoard = xBoard + textWidth; 
    label1.textColor = term1Label.textColor; 
    label1.font = [UIFont italicSystemFontOfSize:textHeight]; 
    label1.textAlignment = term1Label.textAlignment; 
    label1.text = label1String; 
    label1.alpha = 0; 
    label1.backgroundColor = [UIColor clearColor]; 
    [boardView addSubview:label1]; 

    [UIView animateWithDuration:2.0*time 
          delay:timeDelay 
         options:UIViewAnimationOptionCurveEaseInOut 
        animations:^{ 
          label1.alpha = 1; 
        } completion:^(BOOL finished){ 
          } 
       ]; 

    timeDelay = timeDelay + 2.0*time; 

일부 라벨 표시에 대한 일부 변경 색상을 내가 UILabels의 일부 애니메이션을 에 대한 루프를 가지고있다. 두 번째 루프를 만들 때까지 모든 것이 잘 작동합니다. 그런 다음 코드의 첫 번째 부분이 나타납니다 (색상 변경의 애니메이션은 여전히 ​​작동하지만 첫 번째 루프의 모든 레이블이 표시되고 애니메이션되지 않습니다.) 두 번째 루프는 잘 움직입니다.

애니메이션 [UIView animateWithDuration : ...] CABasicAnimations와 대기열과 함께 하나의 NSMutableArray에 저장하지만, 나는 성공하지 못했습니다. 아마도 내 지식이 너무 짧습니다. 어떤 도움을 환영합니다. 감사합니다 !!!!

+0

다른 모든 "연속/등/애니메이션을 어떻게 내포/어떻게 만드나요?"문제가 있습니까? 사소한 변경으로 여러 번 동일한 질문이 제기되었습니다. 이들을 검색해보십시오. 어쩌면 당신은 심지어 오른쪽의 "관련있는"목록에서 뭔가를 볼 것입니다 ... –

답변

0

마지막으로 문제를 해결했습니다. 다음은 올바르게 작동하는 코드입니다

- (void)performAnimations { 
// Finish when there are no more animations to run 

int i = animationNumber; 
int tag = [[[animations objectAtIndex:i]objectAtIndex:0]intValue]; 
int animation = [[[animations objectAtIndex:i]objectAtIndex:1]intValue]; 
float animTime = [[[animations objectAtIndex:i]objectAtIndex:2]floatValue]; 
//float animDelay = [[[animations objectAtIndex:i]objectAtIndex:3]floatValue]; 
float animDelay = 0; 
float parameter = [[[animations objectAtIndex:i]objectAtIndex:4]floatValue]; 

UILabel *label = [UILabel alloc]; 
UIView *view = [UIView alloc]; 
if ([[self.view viewWithTag:tag] isKindOfClass:[UILabel class]]){ 
    label = (UILabel *)[self.view viewWithTag:tag]; 
} else if ([[self.view viewWithTag:tag] isKindOfClass:[UIView class]]) { 
    view = (UIView *)[self.view viewWithTag:tag]; 
} 

switch (animation) { 
    case 1: 
     [self colorizeLabelForAWhile:label withUIColor:[UIColor yellowColor] animated:YES withTime:animTime withDelay:animDelay]; 
     break; 
    case 2: 
     [self appear:label withTime:animTime withDelay:animDelay]; 
     break; 
    case 3: 
     [self disappear:label withTime:animTime withDelay:animDelay]; 
     break; 
    case 4: 
     [self moveView:view withOffset:parameter withTime:animTime withDelay:animDelay]; 
     break; 

    default: 
     break; 
} 
} 

-(void)animationDidFinished{ 
animationNumber = animationNumber + 1; 
if (animationNumber == [[self animations] count]) { 
    [animations removeAllObjects]; 
    return; 
} else { 
    [self performAnimations]; 
} 
} 


-(void)colorizeLabelForAWhile:(UILabel *)label withUIColor:(UIColor *)tempColor animated:(BOOL)animated withTime:(float)time withDelay:(float)delay{ 
UILabel *tempLabel = [[UILabel alloc] init]; 
tempLabel.textColor = tempColor; 
tempLabel.font = label.font; 
tempLabel.alpha = 0; 
tempLabel.textAlignment = label.textAlignment; 
tempLabel.text = label.text; 
tempLabel.backgroundColor = [UIColor clearColor]; 
[label.superview addSubview:tempLabel]; 
tempLabel.frame = label.frame; 

    if (animated) { 
     [UIView animateWithDuration:time 
           delay:delay 
          options:UIViewAnimationOptionCurveEaseInOut 
         animations:^{ 
          // Animate it 
          label.alpha = 0; 
          tempLabel.alpha = 1; 
         } completion:^(BOOL finished){ 
          [UIView animateWithDuration:time 
                delay:0 
               options:UIViewAnimationOptionCurveEaseInOut 
               animations:^{ 
                // Animate it back. 
                label.alpha = 1; 
                tempLabel.alpha = 0; 
               } completion:^(BOOL finished){ 
               // Remove the tempLabel view when we are done. 
                [tempLabel removeFromSuperview]; 
                if (finished) { 
                 [self animationDidFinished]; 
                } 

               }]; 
         }]; 

    } else { 
     // Change it back at once and remove the tempLabel view. 
     label.alpha = 1.0; 
     [tempLabel removeFromSuperview]; 
    } 
} 


-(void)appear:(UILabel *)label withTime:(float)time withDelay:(float)delay{ 
    [UIView animateWithDuration:time 
          delay:delay 
         options:UIViewAnimationOptionCurveEaseInOut 
        animations:^{ 
         label.alpha = 1.0; 
        } completion:^(BOOL finished){ 
         NSLog(@"Anim Appear %d",label.tag); 
         if (finished) { 
          [self animationDidFinished]; 
         } 
        }]; 

} 

-(void)disappear:(UILabel *)label withTime:(float)time withDelay:(float)delay{ 
[UIView animateWithDuration:time 
         delay:delay 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
        label.alpha = 0.0; 
       } completion:^(BOOL finished){ 
        NSLog(@"Anim Disappear %d",label.tag); 
        [label removeFromSuperview]; 
        if (finished) { 
         [self animationDidFinished]; 
        } 

       }]; 

} 

-(void)moveView:(UIView *)view withOffset:(float)offset withTime:(float)time withDelay:(float)delay{ 
[UIView animateWithDuration:time 
         delay:delay 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
        CGRect frame = view.frame; 
        frame.origin.y += offset; 
        view.frame = frame; 
       } completion:^(BOOL finished){ 
        if (finished) { 
         [self animationDidFinished]; 
        } 
       } 
]; 
} 
0

나는 중간에 해결 중입니다 문제. 내 루프 I 무효의 끝 나는 캘리포니아에서 테이블

  NSArray *animation1 = [[NSArray alloc]initWithObjects:[NSNumber  numberWithInt:label1.tag], [NSNumber numberWithInt:3],[NSNumber numberWithFloat:0.5f*time],[NSNumber numberWithFloat:timeDelay],[NSNumber numberWithFloat:0],nil]; 
       [animations addObject:animation1]; 

에 애니메이션 매개 변수를 저장하고 지내요 [self performAnimations];

- (void)performAnimations { 
if ([[self animations] count] == 0) return; 

for (int i=0; i<[[self animations] count]; i++) { 

    int tag = [[[animations objectAtIndex:i]objectAtIndex:0]intValue]; 
    int animation = [[[animations objectAtIndex:i]objectAtIndex:1]intValue]; 
    float animTime = [[[animations objectAtIndex:i]objectAtIndex:2]floatValue]; 
    float animDelay = [[[animations objectAtIndex:i]objectAtIndex:3]floatValue]; 
    float parameter = [[[animations objectAtIndex:i]objectAtIndex:4]floatValue]; 

    UILabel *label = [UILabel alloc]; 
    UIView *view = [UIView alloc]; 
    if ([[self.view viewWithTag:tag] isKindOfClass:[UILabel class]]){ 
     label = (UILabel *)[self.view viewWithTag:tag]; 
    } else if ([[self.view viewWithTag:tag] isKindOfClass:[UIView class]]) { 
     view = (UIView *)[self.view viewWithTag:tag]; 
    } 

    switch (animation) { 
     case 1: 
      [PolyCalcsViewController colorizeLabelForAWhile:label withUIColor:[UIColor yellowColor] animated:YES withTime:animTime withDelay:animDelay]; 
      break; 
     case 2: 
      [PolyCalcsViewController appear:label withTime:animTime withDelay:animDelay]; 
      break; 
     case 3: 
      [PolyCalcsViewController disappear:label withTime:animTime withDelay:animDelay]; 
      break; 
     case 4: 
      [PolyCalcsViewController moveView:view withOffset:parameter withTime:animTime withDelay:animDelay]; 
      break; 

     default: 
      break; 
    } 

} 

[animations removeAllObjects]; 

}

+(void)colorizeLabelForAWhile:(UILabel *)label withUIColor:(UIColor *)tempColor animated:(BOOL)animated withTime:(float)time withDelay:(float)delay{ 
UILabel *tempLabel = [[UILabel alloc] init]; 
tempLabel.textColor = tempColor; 
tempLabel.font = label.font; 
tempLabel.alpha = 0; 
tempLabel.textAlignment = label.textAlignment; 
tempLabel.text = label.text; 
tempLabel.backgroundColor = [UIColor clearColor]; 
[label.superview addSubview:tempLabel]; 
tempLabel.frame = label.frame; 

    if (animated) { 
     [UIView animateWithDuration:time 
           delay:delay 
          options:UIViewAnimationOptionCurveEaseInOut 
         animations:^{ 
          // Animate it 
          label.alpha = 0; 
          tempLabel.alpha = 1; 
         } completion:^(BOOL finished){ 
          [UIView animateWithDuration:time 
                delay:0 
               options:UIViewAnimationOptionCurveEaseInOut 
               animations:^{ 
                // Animate it back. 
                label.alpha = 1; 
                tempLabel.alpha = 0; 
               } completion:^(BOOL finished){ 
               // Remove the tempLabel view when we are done. 
                [tempLabel removeFromSuperview]; 
               }]; 
         }]; 

    } else { 
     // Change it back at once and remove the tempLabel view. 
     label.alpha = 1.0; 
     [tempLabel removeFromSuperview]; 
    } 

}

+(void)appear:(UILabel *)label withTime:(float)time withDelay:(float)delay{ 
    [UIView animateWithDuration:time 
          delay:delay 
         options:UIViewAnimationOptionCurveEaseInOut 
        animations:^{ 
         label.alpha = 1.0; 
        } completion:^(BOOL finished){ 
         NSLog(@"Anim Appear %d",label.tag); 
        }];   
    } 

    +(void)disappear:(UILabel *)label withTime:(float)time withDelay:(float)delay{ 
[UIView animateWithDuration:time 
         delay:delay 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
        label.alpha = 0.0; 
       } completion:^(BOOL finished){ 
        NSLog(@"Anim Disappear %d",label.tag); 
        [label removeFromSuperview]; 
       }];  
     } 

포인트는 그 프로그램이 테이블 애니메이션에 어떻게 순차적으로 애니메이션을 수행하지이다. 이전 애니메이션이 끝나면 시간 지연을 포기하고 다음 애니메이션을 실행해야한다고 생각합니다. 내가 완료에서 카운터를 만들 수 있습니다 : (BOOL 완료) 블록,하지만 어떻게 함수가 외부 변수를 허용하지 않기 때문에 모르겠어요. 모든 아이디어를 어떻게 애니메이션의 끝을 감지하고 테이블 실행을 제어? 감사.