Tib*_*bbe 13 objective-c uiwebview uiimageview uiactivityindicatorview ios
我正在加载一个UIWebView,同时我不想用这个显示一个空白页面
活动指示器旋转(siri活动指示器).根据我的理解,你无法改变图像,但我不能使用该图像并创建一个旋转360°并循环的动画?还是会耗尽电池?
像这样的东西?:
- (void)webViewDidStartLoad:(UIWebView *)webView {
//set up animation
[self.view addSubview:self.loadingImage];
//start animation
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//stop animation
[self.loadingImage removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
提前致谢!
dem*_*ten 33
其中大部分都可以在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"];
}
Run Code Online (Sandbox Code Playgroud)
在我的layoutSubviews方法中,我启动了旋转.您可以将它放在您的身上webViewDidStartLoad,webViewDidFinishLoad如果这对您的情况更好:
- (void)layoutSubviews
{
[super layoutSubviews];
// some other code
[Utils rotateLayerInfinite:_activityIndicatorImage.layer];
}
Run Code Online (Sandbox Code Playgroud)
你可以随时停止旋转 [_activityIndicatorImage.layer removeAllAnimations];
| 归档时间: |
|
| 查看次数: |
33671 次 |
| 最近记录: |