Krisiacik / ImageViewer

An image viewer à la Twitter
MIT License
2.53k stars 385 forks source link

Disabling spinner (UIActivityIndicatorView) #167

Open olexth opened 6 years ago

olexth commented 6 years ago

Hello! First of all, thanks for such a great library!

QUESTION: I need to disable spinner by one of my events. I created my custom VC and adding an instance of GalleryViewController in such manner:

   override func viewDidLoad() {
        super.viewDidLoad()

        controller = GalleryViewController(startIndex: 0, itemsDataSource: self, displacedViewsDataSource: nil, configuration: galleryConfiguration())

        controller.loadViewIfNeeded()
        addChildViewController(controller)
        view.addSubview(controller.view)
        controller.didMove(toParentViewController: self)
    }

What's the proper way to get currently used UIActivityIndicator to disable it when there is no internet connection?(indicator stays on screen and rotates infinitely)

Thanks in advance!

olexth commented 6 years ago

So, currently I made this through view hierarchy, which is very ugly:

let childViewController = self.controller.childViewControllers[0]
                    if let imageViewController = childViewController as? ItemBaseController<UIImageView> {
                        for view in imageViewController.view.subviews {
                            if let indicator = view as? UIActivityIndicatorView {
                                indicator.stopAnimating()
                            }
                        }
                    }

Would be glad to receive any comment on a question.

Best regards, Alex