2013-08-22 2 views
0

메신저를 유지해야하고, 내가 어떤 helpfull 코드를 발견IOS는 이미지를 회전하고있는 UIImageView 회전하고자하는 애니메이션으로,이

- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations: (CGFloat)rotations repeat:(float)repeat; 
{ 
    CABasicAnimation* rotationAnimation; 
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ]; 
    rotationAnimation.duration = duration; 
    rotationAnimation.cumulative = YES; 
    rotationAnimation.repeatCount = repeat; 

    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 

} 

문제는 이미지가 때 애니메이션이 완료, 메신저 다시 뒤집이다 그것을 돌리고 거기에 그것을 지키기 위해. 실제 이미지를 뒤집을 필요가 있을지 아니면 ImageView를 뒤집을 수 있습니까? 그리고 어떻게 그럴 수 있니?

+0

이 작업을 수행해야합니다. 'rotationAnimation.removedOnCompletion = NO;' – BooRanger

+0

작동하지 않고 계속 뒤집습니다. –

+0

' dispatch_after' 블록을 호출하고'view.transform.rotation.z'를 원하는 값으로 디스패치합니다. 해킹 조금하지만 작동해야합니다. – Majster

답변

-1

내 모든베이스를 CoreAnimation으로 덮는 것을 선호합니다. 애니메이션 전에 최종 값을 설정하고 채우기 모드를 설정하고 제거하지 않도록 설정하십시오.

- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:   (CGFloat)rotations repeat:(float)repeat; 
{ 
    NSString * animationKeyPath = @"transform.rotation.z"; 
    CGFloat finalRotation = M_PI * 2.0f * rotations; 
    [view.layer setValue:@(finalRotation) forKey:animationKeyPath]; 

    CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:animationKeyPath]; 
    rotationAnimation.fromValue = @0.0f; 
    rotationAnimation.toValue = @(finalRotation); 
    rotationAnimation.fillMode = kCAFillModeBoth; 
    rotationAnimation.removedOnCompletion = NO; 
    rotationAnimation.duration = duration; 
    rotationAnimation.cumulative = YES; 
    rotationAnimation.repeatCount = repeat; 

    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 
} 
0

UIView animation 표준을 사용하지 않는 이유는 무엇입니까? 당신이 autoreverse 같은 다른 옵션이 필요하면

[UIView animateWithDuration:duration animations:^{ 
    yourView.transform = CGAffineTransformMakeRotation(angle); 
} completion:^(BOOL finished) { 
    // your completion code here 
}] 

: 당신이 많이 선호하는 새로운 스타일을 사용할 수 있습니다, 그렇지 않으면

[UIView beginAnimations] 
[UIView setAnimationRepeatCount:repeatCount]; 
[UIView setAnimationDuration:duration]; 
yourView.transform = CGAffineTransformMakeRotation(degrees * M_PI); 
[UIView commitAnimations]; 

: 당신이 정말로 repeatCount 필요한 경우 , 그럼 난 당신이 이전 스타일을 사용하는 것이 좋습니다 사용자 상호 작용 또는 반복 사용 허용 [UIView animateWithDuration:delay:options:animations:completion:];

관련 문제