I am loading a UIWebView
and in the meantime I wan't to show a blank page with this activity indicator spinning (siri activity indicator). From what I have understand you can not change the image, but can't I use that image and create an animation with it rotating 360° and looping? Or will that drain the battery?
像这样的东西?:
- (void)webViewDidStartLoad:(UIWebView *)webView {
//set up animation
[self.view addSubview:self.loadingImage];
//start animation
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//stop animation
[self.loadingImage removeFromSuperview];
}
我应该怎么办?
提前致谢!
其中大部分可以在 Stack Overflow 中找到。让我总结一下:
创建一个 UIImageView ,它将用作活动指示器(在故事板场景、NIB、代码......任何您想要的地方)。我们就这样称呼它吧_activityIndicatorImage
加载您的图像:_activityIndicatorImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"activity_indicator"]];
您需要使用动画来旋转它。这是我使用的方法:
+ (void)rotateLayerInfinite:(CALayer *)layer
{
CABasicAnimation *rotation;
rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
rotation.duration = 0.7f; // Speed
rotation.repeatCount = HUGE_VALF; // Repeat forever. Can be a finite number.
[layer removeAllAnimations];
[layer addAnimation:rotation forKey:@"Spin"];
}
在我的layoutSubviews方法中我启动旋转。你可以把它放在你的webViewDidStartLoad
and webViewDidFinishLoad
如果这更适合您的情况:
- (void)layoutSubviews
{
[super layoutSubviews];
// some other code
[Utils rotateLayerInfinite:_activityIndicatorImage.layer];
}
你总是可以使用停止旋转[_activityIndicatorImage.layer removeAllAnimations];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)