ios:当我向我的服务器发送请求以控制刷新图像旋转360°时如何动画

时间:2015-08-06 07:43:10

标签: ios animation rotation

因此,当标题,当网络请求回调时,以这种方式停止动画:如果请求立即返回,它将在360度旋转后停止,以便在动画工作之前恢复。如果它是时间如此lang,它将在360 *(整数)度后停止。 我能做些什么来控制它完美? 我的编程语言是Objective-C。

2 个答案:

答案 0 :(得分:0)

Last night i solved this,but it's not perfect First,creat an animation:

- (void)initAnimation{
[CATransaction begin];
CGFloat angle = 1000000 * 360 * M_PI/180.0;
refreshAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
refreshAnimation.byValue = @(angle);
refreshAnimation.duration = 1.0 * 1000000;
refreshAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
refreshAnimation.removedOnCompletion = YES;

[CATransaction commit];

}

Second,before send request, add the animation to the imageView:

    - (void)sendRequst{
[refreshImageView.layer addAnimation:refreshAnimation forKey:@"rotationAnimation"];
[self sendRequstToSever];

}

Finally,when the server feedback,remove the animation and set the imagView to the original position:

- (void)changeAnimationStatus{
[refreshImageView.layer removeAnimationForKey:@"rotationAnimation"];
[UIView animateWithDuration:0.30 animations:^{
    refreshImageView.transform = CGAffineTransformRotate(self.view.transform, 0.0);
}];}

答案 1 :(得分:0)

CGFloat angle = 2 * M_PI;
refreshAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
refreshAnimation.delegate = self;
refreshAnimation.removedOnCompletion = NO;
refreshAnimation.repeatCount = CGFLOAT_MAX;
refreshAnimation.additive = YES;
refreshAnimation.byValue = @(angle);
refreshAnimation.duration = 0.9 ;
refreshAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animationStamp = [[NSDate date] timeIntervalSince1970];
[btn.layer addAnimation:refreshAnimation forKey:@"rotationAnimation"];

然后用时间来解决这个问题