Rotating Image multiple times and stopping at desi

2019-08-27 18:03发布

i had tried various method and couldn't figure out how to achieve this.i searched on internet a lot but can't figure out.

i have an ImageView (a wheel which spins) , i want to rotate it by 360 degree for 10 times(this is to just give user feel of fast turning wheel) , and then i want to rotate it by particular value say 90 degree( but it might be varying).

after this animation finishes i want to bring ImageView back to the initial position.

how do i achieve this ? Thanks in advance.

1条回答
对你真心纯属浪费
2楼-- · 2019-08-27 18:37

well i found out how to do this. i used below method to rotate by 360 degree for 10 times , and then rotate by particular degree.

-(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];
        }];

 }];

}

below method is used to reset image to original position.

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

          self.scoreImageView.transform = CGAffineTransformIdentity;
    }]; 
}
查看更多
登录 后发表回答