gpt4 book ai didi

ios - 在后台触摸时关闭 UIActivityIndi​​catorView

转载 作者:行者123 更新时间:2023-11-29 10:52:31 25 4
gpt4 key购买 nike

我正在从 Web 服务获取数据,在获取数据期间,我在屏幕上显示了一个 UIAcitivityIndi​​catorView。这个指标在 UIAlertView

UIAlertView *waitAlert = [[UIAlertView alloc] initWithTitle:@"Please Wait...." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];

[waitAlert show];

indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(waitAlert.bounds.size.width / 2, waitAlert.bounds.size.height - 50);
[waitAlert addSubview:indicator];

NSURL *url = [NSURL URLWithString:URLString];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSThread detachNewThreadSelector:@selector(startAnimation) toTarget:self withObject:self.view];


[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
// Data to populate the tableview
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {

[self.tableView1 reloadData];
//Stop the UIActivitiyIndicatorView
[self stopLoading];

}];
}];

当数据成功加载时,我可以成功关闭它,但如果有人在从 Web 服务加载数据期间触摸屏幕的其余部分,我想关闭 UIActivityIndi​​catorView。任何帮助将不胜感激。

最佳答案

你能试试这个吗

显示 UIAlertView 后,将 View 添加到您的 View Controller (或什至窗口)新的全屏大小的空 UIView。使用 UITapGestureRecognizer 附加到此 View

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[view addGestureRecognizer:singleTap];
[singleTap release];

-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
[myAlert dismissWithClickedButtonIndex:0 animated:YES];
[view removeFromSuperView];
}

关于ios - 在后台触摸时关闭 UIActivityIndi​​catorView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19876077/

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