Rotating Image multiple times and stopping at desired degree?

ⅰ亾dé卋堺 提交于 2019-12-25 09:47:19

问题


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:


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


来源:https://stackoverflow.com/questions/44854367/rotating-image-multiple-times-and-stopping-at-desired-degree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!