我想在调用API或任何后台方法时在uiview中添加一个加载器。它有任何默认值吗?或者我已经创建了自定义加载器。
答案 0 :(得分:1)
试试这个:
{
"environment": "PROD",
"auto_renew_status": "false",
"latest_expired_receipt_info": {
"original_purchase_date_pst": "2018-01-25 11:59:25 America/Los_Angeles",
"cancellation_date_ms": "1517150504000",
"cancellation_reason": "0",
"original_purchase_date_ms": "1516910365000",
"expires_date_formatted": "2019-01-25 19:59:23 Etc/GMT",
"is_in_intro_offer_period": "false",
"purchase_date_ms": "1516910363000",
"expires_date_formatted_pst": "2019-01-25 11:59:23 America/Los_Angeles",
"is_trial_period": "false",
"expires_date": "1548446363000",
"cancellation_date": "2018-01-28 14:41:44 Etc/GMT",
"purchase_date": "2018-01-25 19:59:23 Etc/GMT",
"cancellation_date_pst": "2018-01-28 06:41:44 America/Los_Angeles",
"purchase_date_pst": "2018-01-25 11:59:23 America/Los_Angeles",
"original_purchase_date": "2018-01-25 19:59:25 Etc/GMT"
},
"cancellation_date_ms": "1517150504000"
}
现在可以在任何地方调用它 -
-(void)loaderType1 :(UIView *)View
{
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=View.center;
activityView.color=(UIColor*)[UIColor blackColor]; //change color
activityView.tag=10;
[activityView startAnimating];
//this is for freeze UI when loader appears
//[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
//this is for stop the previous action
//[[UIApplication sharedApplication] endIgnoringInteractionEvents];
[View addSubview:activityView];
[View bringSubviewToFront:activityView];
}
删除装载程序:
[self loaderType1: self.view];
答案 1 :(得分:1)
是的,iOS中有默认的activityIndicator。你可以这样添加。
class ViewController: UIViewController {
let activityIndicator = UIActivityIndicatorView()
override func viewDidLoad() {
super.viewDidLoad()
activity.center = view.center
// Customization
activityIndicator.color = UIColor.blue
activityIndicator.activityIndicatorViewStyle = .gray
view.addSubview(activityIndicator)
}
}
开始动画制作你想要的地方:
activityIndicator.startAnimating()
停止动画制作你想要的地方:
activityIndicator.stopAnimating()
从视图中删除:
activityIndicator.removeFromSuperview()
答案 2 :(得分:0)
@property UIActivityIndicatorView * spinner;
_spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[self.view addSubview:_spinner];
[_spinner setFrame:CGRectMake(0, 0, 100, 100)];
_spinner.center = self.view.center;
_spinner.transform = CGAffineTransformMakeScale(2, 2);
[_spinner setColor:[UIColor darkGrayColor]];
//Now start spinner where you want
[self.view bringSubviewToFront:_spinner];
[_spinner startAnimating];
//Stop spinner
dispatch_async(dispatch_get_main_queue(), ^{
[_spinner stopAnimating];
});
答案 3 :(得分:0)
试试这个,您可以在基本uiviewcontroller中编写/粘贴以下代码,并在需要显示/隐藏加载栏时调用相应的/当前viewcontroller。
请注意,我们可以使用UILabel播放/优化阻止视图,例如加载或自定义文本。
-(void)makeScreenBusy {
if(!self.spinner){
[self createSpinner];
}
[self.view addSubview:self.blockerView];
[self.blockerView setAlpha:0];
self.spinner.center = self.blockerView.center;
[UIView animateWithDuration:kMinimumAnimationDuration animations:^{
[self.blockerView setAlpha:0.5];
[self.spinner startAnimating];
}];
}
-(void)makeScreenAvailable {
[UIView animateWithDuration:kMinimumAnimationDuration animations:^{
[self.blockerView setAlpha:0];
[self.spinner stopAnimating];
}completion:^(BOOL finished) {
[self.blockerView removeFromSuperview];
}];
}
-(void)createSpinner {
[self.blockerView setFrame:[UIScreen mainScreen].bounds];
[self.blockerView setAlpha:0.5];
self.spinner = [[UIActivityIndicatorView alloc] init];
[self.spinner setBackgroundColor:[UIColor clearColor]];
[self.spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[self.blockerView addSubview:self.spinner];
}