use MBProgressHUD, it displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. MBPreogressHUD, see example for more details
Loading indicator for iOS7 while request is being made to server
-
30-07-2022 - |
Вопрос
I want to use a some form of loading display while a background thread is being executed. I had considered using an Activity Indicator view
but I feel it is not enough by itself. I would like to be able to prevent user interaction while loading is going on, therefore I thought about a hosting it on a UIAlertView. However I saw that Apple states that you The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
As a result I'm hesitant to put a loading indicator into a UIAlertView.
I had a look at other examples here, some which suggest the Custom UIAlertView
approach. I am just wondering what is the best approach or some direction?
Am I correct in thinking the app will be refused if I customise the UIAlertView?
Thanks
Решение
Другие советы
I have done something like this. What I did was I used a translucent black view covering the whole window. Trap any events in this overlay to prevent clicking through on components below. This is acceptable, the app is in the App Store.
Take a look at MBProgressHUD - built exactly for this - https://github.com/jdg/MBProgressHUD
You can use MBProgressHUD standard library for it. Download it from this link
Shortly you can do it like this:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[MBProgressHUD hideHUDForView:self.view animated:YES];
This MBProgressHUD link will help you to understand it
- Create notification and fire it back to the main thread in callout block of asynchronous thread.
- Create new special Activity View Controller with translucent
self.view
and addUIActivityView
on it. Trap UIEvents on customized view and set it as self.view. - Add this controller as listener to notification.
- When asynchronous process starts, add this view controller as child controller to existing controller, same with the self.view.
- When notification reached Activity View Controller notification triggered method, remove its view from superview, same with view controller, t.i. Activity View Controller.
In this way you will be more flexible to do anything you want with it.