2013-02-05 2 views
1

ECG (하트 비트 모니터)와 같은 연속 펄스 효과를 얻고 싶습니다. 현재 두 개의 애니메이션 블록을 사용하고 있습니다.두 애니메이션 사이에 UIViewAnimationOptionRepeat 일시 중지

[UIView animateWithDuration: 2.0f delay: 0.0f options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionTransitionNone | UIViewAnimationOptionOverrideInheritedDuration 
       animations:^{ [image1 setFrame:CGRectMake(0,200,320,70)];} 
       completion:^(BOOL finished){[image1 setFrame:CGRectMake(-320,200,320,70)];}]; 

[UIView animateWithDuration:2.0f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionTransitionNone | UIViewAnimationOptionOverrideInheritedDuration 
       animations:^{ [image2 setFrame:CGRectMake(320,200,320,70)];} 
       completion:^(BOOL finished){[image2 setFrame:CGRectMake(0,200,320,70)];}]; 
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; 

[UIView commitAnimations]; 

완성 후이 애니메이션의 투여를 반복하지만, 내가 사이에 그 일시 정지를 제거하고 지속적이고 부드러운 애니메이션을 달성하고자 .. 다시보고하기 전에 약간의 일시 정지됩니다 ..

In case I'm not clear to you, i want to achieve this kind of effect..

사전에 모든 간염이 많이 주시면 감사하겠습니다

..

감사합니다 ..

당신은 내가 알고 너무 또한 UIViewAnimationCurveEaseInOut을 시도했습니다. 그러나 여전히 일시 중지됩니다.

+0

첫 번째 의견 : setAnimationCurve : "이 메서드는 애니메이션 블록 외부에서 호출하면 아무 작업도 수행하지 않습니다." – meronix

+0

second : beginAnimations : context :가 호출되지 않으면 commitAnimations는 사용되지 않습니다. – meronix

+0

@meronix : 시도해보기 위해 setAnimationCurve : 메소드를 추가했습니다. 그러나 나는 그 방법을 추가하기 전에 부드럽게 움직이지 않았습니다. –

답변

4

마지막으로 알아 냈습니다 ... 코드를 사용하여 부드럽고 일시 중지되지 않는 애니메이션을 얻었습니다.

[UIView animateWithDuration:2.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveLinear 
       animations:^{ [image1 setFrame:CGRectMake(0,200,320,70)];} 
       completion:^(BOOL finished){}]; 

[UIView animateWithDuration:2.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveLinear 
       animations:^{ [image2 setFrame:CGRectMake(320,200,320,70)];} 
       completion:^(BOOL finished){}]; 

중요한 변화는 내가 UIViewAnimationOptionCurveLinearUIViewAnimationCurveLinear를 교체해야했다.

1

이것은 일시 중지없이 작동합니다.

당신은 단지 위치, 아니 크기를 변경, 그래서

float originalX = image1.center.x; 
[UIView animateWithDuration: 2.0f delay: 0.0f options: UIViewAnimationCurveLinear | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction       
      animations:^{ image1.center = CGPointMake(originalX + 320, image1.center.y);} 
         completion:^(BOOL finished){}]; 

은 당신이 정말로 완료 블록의 원래 위치를 설정할 필요가 없습니다 프레임 대신에 중심을 변경하는 것이 더 나은 될 수는 " 반복 "옵션을 사용합니다.

관련 문제