gpt4 book ai didi

ios - 当 webView 完成加载时,事件指示器不会消失

转载 作者:行者123 更新时间:2023-11-28 22:02:04 25 4
gpt4 key购买 nike

我正在使用 Objective-c 开发 iOS 应用程序。然后,我正在实现自定义的 Activity Indicator,它在加载 webView 时处于事件状态。

自定义的 Activity Indicator 在 webView 开始加载时出现,但是当 webView 完成加载时它不会消失。

我的代码如下。

你能告诉我如何解决这个问题吗?

@interface DetailViewController ()<UIWebViewDelegate>{
{
UILabel *loadingLabel;
UIActivityIndicatorView *loadingMark;
UIView *loadingContainer;
}
@property (weak, nonatomic) IBOutlet UIWebView *detailPage;
@end

@implementation DetailViewController

- (void)configureView
{
NSURL *page_url = [NSURL URLWithString:@"http://yahoo.co.jp"];
NSURLRequest *request = [NSURLRequest requestWithURL:page_url];
[_detailPage loadRequest:request];
_detailPage.delegate = self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)webViewDidStartLoad:(UIWebView*)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self animatingIndicator];
}


- (void)webViewDidFinishLoad:(UIWebView*)webView
{
[self stopAndRemoveIndicator];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

-(void)animatingIndicator {

loadingContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 60)];

//Set Style Of Label
loadingLabel = [[UILabel alloc] init];
loadingLabel.text = @"Loading";
loadingLabel.textColor = [UIColor whiteColor];
loadingLabel.shadowColor = [UIColor blackColor];
loadingLabel.shadowOffset = CGSizeMake(1, 1);
loadingLabel.font = [UIFont boldSystemFontOfSize:17];
loadingLabel.backgroundColor = [UIColor lightGrayColor];
loadingLabel.frame = CGRectMake(20, 17, 70, 25);
[loadingContainer addSubview:loadingLabel];

//Set Style Of Mark
loadingMark = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
loadingMark.frame = CGRectMake(100, 14, 30, 30);
[loadingContainer addSubview:loadingMark];

//Set Style Of Container
loadingContainer.backgroundColor = [UIColor lightGrayColor];
[[loadingContainer layer] setCornerRadius:8.0f];
[[loadingContainer layer] setMasksToBounds:YES];
[[loadingContainer layer] setBorderWidth:0.5f];
[[loadingContainer layer] setBorderColor:[[UIColor darkGrayColor] CGColor]];
CGRect rect = self.view.frame;
loadingContainer.center = CGPointMake(rect.size.width/2, rect.size.height/2 * 0.8);
[self.view addSubview:loadingContainer];

[loadingMark startAnimating];
loadingContainer.hidden = NO;
}

-(void)stopAndRemoveIndicator {
[loadingMark stopAnimating];
loadingContainer.hidden = YES;
[loadingMark setHidden:YES];
}

最佳答案

您需要在主线程中隐藏 UIKit 对象。

override func webViewDidFinishLoad(webView:UIWebView)
{
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.loadingSign.stopAnimating()
self.loadingSign.hidden = true
}
}

swift 4 更新

override func webViewDidFinishLoad(_ webView: UIWebView)
{
DispatchQueue.main.async {
self.loadingSign.stopAnimating()
self.loadingSign.hidden = true
}
}

关于ios - 当 webView 完成加载时,事件指示器不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24871062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com