2017-06-30 4 views
0

j'avais essayé diverses méthodes et ne pouvais pas comprendre comment y parvenir.je cherchais sur internet beaucoup, mais ne peux pas comprendre.Rotation de l'image plusieurs fois et arrêt au degré désiré?

j'ai un ImageView (une roue qui tourne), je veux le faire pivoter de 360 ​​degrés pour 10 fois (ce qui est juste donner la sensation utilisateur de la roue tournant rapide), puis je veux le faire tourner par valeur particulière dire 90 degrés (mais il pourrait être variable).

Une fois cette animation terminée, je souhaite ramener ImageView à la position initiale.

Comment puis-je y parvenir? Merci d'avance.

+0

Comment faites-vous tourner la vue de l'image? – AdamPro13

+0

j'ai tourné avec CGAffineTransformMakeRotation. J'ai également essayé avec [CABasicAnimation animationWithKeyPath: @ "transform.rotation.z"] –

+0

Essayez d'appliquer 'CGAffineTransformIdentity' à la fin pour le renvoyer à l'état d'origine. – AdamPro13

Répondre

0

bien j'ai trouvé comment faire ceci. J'ai utilisé ci-dessous la méthode pour faire pivoter de 360 ​​degrés pendant 10 fois, puis tourner d'un degré particulier.

-(void)rotate:(int)degreeToRotate 
{ 
    CGFloat radians = (M_PI/180) * degreeToRotate; 
    [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations: ^{ 
    //configuring to rotate 360 degree 10 times 
    CABasicAnimation* rotationAnimation; 
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ]; 
    rotationAnimation.cumulative = YES; 
    rotationAnimation.repeatCount = 10; 

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

    } completion:^(BOOL finished) { 
     //rotate by particular degree 
     [ UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
     // -radians, to ensure clockwise rotation 
     self.scoreImageView.transform = CGAffineTransformMakeRotation(-radians); 

     } completion:^(BOOL finished) { 
       //method call to reset image original position 
       [self performSelector:@selector(resetPosition) withObject:nil afterDelay:3]; 
     }]; 

}]; 

} 

ci-dessous la méthode utilisée pour réinitialiser l'image à la position initiale.

-(void)resetPosition 
{ 
    [UIView animateWithDuration:0.2 animations:^() { 

      self.scoreImageView.transform = CGAffineTransformIdentity; 
    }]; 
}