mrackwitz / MRProgress

Collection of iOS drop-in components to visualize progress
MIT License
2.55k stars 306 forks source link

MRProgressOverlayView not Animating in Modal Views #107

Closed MichelleMcCabe closed 8 years ago

MichelleMcCabe commented 8 years ago

Hi, I'm using the latest version of MRProgress within a Swift project. Xcode version 6.4. Deployment target 8.1. I added the MRProgress components to my project via cocoa pods.

pod 'MRProgress'

The amount of detail below is for you to use as input when trying to replicate the behaviour. I'm probably including too much information, but rather that than too little.

I have one storyboard with two views. “Sign In” and “Register”. I have another storyboard with a “Select Location” view that I re-use in a few places. The flow of how the views are presented is as follows:

The “Sign In” view has a segue on the Storyboard to the “Register” view. The segue is "Present Modally". Whilst registering, the user has to select which location they are registering for. On the “Register” view, there is a button to select a location. (After a location is selected, the delegate method will send back the selected location to the “Register” view.)

This is the code behind the “Select Location” button on the “Register” View:

//create an instance of the Select Location view controller and set self as delegate
//============================================
 let searchStoryboard: UIStoryboard = UIStoryboard(name: "Search", bundle: nil)

//get a handle to select Location Viewcontroller in the Search storyboard
let selectLocationViewController = searchStoryboard.instantiateViewControllerWithIdentifier("SelectLocationViewController") as? SelectLocation

//current view controller is the delegate of the select location viewcontroller - it will catch the select location event when it is envoked
selectLocationViewController?.delegate = self

//present the select location viewcontroller
self.presentViewController(selectLocationViewController!, animated: true, completion: nil)

Now the Select Location View is presented. In the swift file of the “Select Location” view, I have this statement at the top:

import MRProgress

Just below the class SelectLocation: UITableViewController, UISearchBarDelegate {, I have the following line:

//progress view
var progressIndicatorView = MRProgressOverlayView.new()

Inside ViewDidLoad() of the “Select Location” view, I have the following:

self.view.addSubview(self.progressIndicatorView)
self.progressIndicatorView.show(true)

…method to make a call to a web service & when done or error…

//hide the progress view
self.progressIndicatorView.dismiss(true)

The MRProgressOverlayView is shown as in the screenshot below, but the blue circle is just static (as you see it in the image below) it does not “turn”.

screenshot_004_2

If I use exactly the same methods on any other view that is not presented modally, the image does animate without a problem.

I hope this provides you with sufficient detail to have a look at it. Let me know if you have any questions.

Thanks.

mrackwitz commented 8 years ago

Hey Michelle,

no worries for including way to much information, you're welcome. But you're right, that was just to much. See above, I deliberately edited your issue to make use of Markdown, which renders code with syntax highlighting and make it a whole lot easier for project maintainers and other users to read / skim even such amount of info.

The solution for your issue is:

  1. Declare your var like that:

    var progressIndicatorView: MRProgressOverlayView?
  2. Add the overlay like that in your viewWillAppear (not inviewDidLoad):

    self.progressIndicatorView = MRProgressOverlayView.showOverlayAddedTo(self.view, animated: true)

By the way, you don't necessarily need a var in your controller to keep a reference to the progress indicator. My recommendation would be to use the provided class methods, as long as you don't want to inform the user about further progress or modify the indicator's appearance while it is shown. You can hide then the overlay, even if you don't hold a direct reference to it, by calling:

MRProgressOverlayView.dismissOverlayForView(self.view)

Keep going!