DragonCherry / AssetsPickerViewController

Powerfully Customizable - Multiple Photo & Video Picker Controller
MIT License
388 stars 136 forks source link

Display HUD/Activity Indicator while importing selected assests #78

Closed kalaichelvan closed 4 years ago

kalaichelvan commented 4 years ago

Hi,

This is awesome library.

I am getting UIImage of selected assets and then save them locally in documents folder. As some of the assets are from cloud, it takes a while to import all the images. Is there a way to display the Hud view or activity indicator while importing the assets from library?

I attempted following but nothing helps:

  1. self.window?.rootViewController?.showHud("Importing...")

  2. UIApplication.shared.windows.last?.showLoading(animated: true, color: .systemBlue, dimColor: .systemGray, alpha: 1.0, verticalRatio: 10, isBlock: true)

  3. if let topVC = UIApplication.getTopViewController() { topVC.showHud("Importing...") }

//getTopViewController

```

class func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {

    if let nav = base as? UINavigationController {
        return getTopViewController(base: nav.visibleViewController)

    } else if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
        return getTopViewController(base: selected)

    } else if let presented = base?.presentedViewController {
        return getTopViewController(base: presented)
    }
    return base
}

//showHud Method

func showHud(_ message: String) { let hud = MBProgressHUD.showAdded(to: self.view, animated: true) let nvaview = NVActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50), type: .lineScale , color: .systemBlue, padding: nil) hud.mode = .customView hud.customView = nvaview hud.bezelView.color = UIColor.white hud.bezelView.style = .solidColor nvaview.startAnimating() hud.label.textColor = UIColor.systemBlue hud.label.text = message view.isUserInteractionEnabled = false hud.isUserInteractionEnabled = false }



Any Help?
kalaichelvan commented 4 years ago

Alright.

Managed to get it done with the help of

DispatchQueue.global(qos: .background).async {
    // Background Thread

    DispatchQueue.main.async {
        // Run UI Updates or call completion block

    }
}