ios:How 动画,同时我向服务器发送请求以控制刷新图像旋转 360°

ios:How to an animation while i send request to my sever to control the refresh image rotate 360°

如题,当net请求回调时,停止动画在这个way:if请求中立即返回,旋转360度后会停止,恢复到动画工作前。如果时间太长,它将在 360 *(整数)度后停止。 我该怎么做才能完美控制它? 我的编程语言是 Objective-C.

昨晚我解决了这个问题,但它并不完美 首先,创建一个动画:

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

}

其次,在发送请求之前,将动画添加到imageView:

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

}

最后,当服务器反馈时,去掉动画,将imagView设置到原来的位置:

- (void)changeAnimationStatus{
[refreshImageView.layer removeAnimationForKey:@"rotationAnimation"];
[UIView animateWithDuration:0.30 animations:^{
    refreshImageView.transform = CGAffineTransformRotate(self.view.transform, 0.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"];

那就抓紧时间解决这个问题