2013-06-13 4 views
0

CGAffineTransformMakeRotationCGAffineTransformRotate을 사용하여 이미지를 회전하려고했습니다. 원본에서 시계 방향으로 이미지를 회전시키고 싶습니다 (0도에서 360도까지와 같이). 이미지를 플레이어에서 CD처럼 회전해야합니다.이미지를 원래 이미지에서 다시 회전하는 방법은 무엇입니까?

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.1]; 
CGAffineTransform transform = CGAffineTransformMakeRotation(1.0); 
transform = CGAffineTransformRotate(transform, -180); 
ImageView.transform = transform; 

[UIView commitAnimations]; 

은 그냥 정도 (180)에 회전하고, 내가 -300로 변경하는 경우는 (i가 필요하지 어떤 것을) 시계 반대 방향으로 회전합니다 :이 같은 일을했다. 내가 뭘 잘못했는지 모르겠다. 누가 말해 줄 수 있니?

답변

0

회전 각도는 중심선의 두 점은 atan2() 가정하자 A와 B에 의해 더 나은 제공되는 이미지는 회전 각도는이

을하는 데 도움이

0-atan2((b.x - a.x) ,(b.y -a.y))

희망입니다 회전하는 것입니다

0
Try this : 

-(void)startAnimationWithRevolutions:(float)revPerSecond forTime:(float)time 
{ 
    spinWheel.userInteractionEnabled = FALSE; 
    float totalRevolutions = revPerSecond * time; 
    [CATransaction begin]; 
[CATransaction setValue:[NSNumber numberWithFloat:time] forKey:kCATransactionAnimationDuration]; 

    CABasicAnimation* spinAnimation = [CABasicAnimation 
             animationWithKeyPath:@"transform.rotation"]; 
    CGAffineTransform transform = spinWheel.transform; 
    float fromAngle = atan2(transform.b, transform.a); 
    float toAngle = fromAngle + (totalRevolutions*4*M_PI); 
    spinAnimation.fromValue = [NSNumber numberWithFloat:fromAngle]; 
    spinAnimation.toValue = [NSNumber numberWithFloat:toAngle]; 
    spinAnimation.repeatCount = 0; 
    spinAnimation.removedOnCompletion = NO; 
    spinAnimation.delegate = self; 
    spinAnimation.timingFunction = [CAMediaTimingFunction functionWithName: 
            kCAMediaTimingFunctionEaseOut]; 
    [spinWheel.layer addAnimation:spinAnimation forKey:@"spinAnimation"]; 
    [CATransaction commit]; 
} 
0

사용이 :

[UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.1]; 
    [UIView animateWithDuration:0.1 animations:^{ 
     CGAffineTransform transform = CGAffineTransformMakeRotation(1.0); 
     transform = CGAffineTransformRotate(transform, -180); 
     ImageView.transform = transform; 
    } completion:^(BOOL finished) { 
     CGAffineTransform transform = CGAffineTransformMakeRotation(0); 
     transform = CGAffineTransformRotate(transform,0); 
     ImageView.transform = transform; 
    }];