0

I'm trying to do the activity indicator with a background that covers the entire screen. My problem is that when I run the app, it only covers a portion of the screen. I am not sure what I am doing wrong here.

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        self.dismissViewControllerAnimated(true) { () -> Void in

            self.activityIndicator = UIActivityIndicatorView(frame: self.view.frame)
            self.activityIndicator.backgroundColor = UIColor(white: 1.0, alpha: 0.5)
            self.activityIndicator.center = self.view.center
            self.activityIndicator.hidesWhenStopped = true
            self.activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
            self.view.addSubview(self.activityIndicator)
            self.activityIndicator.startAnimating()
            UIApplication.sharedApplication().beginIgnoringInteractionEvents()

            print("save the data on to core data and onto Parse, then segue to the new input controller")

            let file = PFFile(data: UIImageJPEGRepresentation(image, 1.0)!)
            let insurance = PFObject(className: "Insurance")

            insurance["userId"] = PFUser.currentUser()?.objectId
            insurance["imageFile"] = file as PFFile
            insurance.saveInBackgroundWithBlock({ (success, error ) -> Void in
                self.activityIndicator.stopAnimating()
                UIApplication.sharedApplication().endIgnoringInteractionEvents()
                if (success) {
                    self.performSegueWithIdentifier("segueToDetails", sender: self)
                }else{
                    self.displayAlert("Problems Savings", message: "There was an error with saving the data")
                }
            })
        }
    }

Display with the code above

Are there any suggestions?

1
  • Apply the constraints to it as centerx and centery to the superview Dec 4, 2015 at 18:20

2 Answers 2

1

Change this line

self.activityIndicator = UIActivityIndicatorView(frame: self.view.frame)

to

self.activityIndicator = UIActivityIndicatorView(frame: self.view.bounds)

Judging from your screenshot, the frame of self.view is something like (0, 64, /* some width */, /* some height */). The y origin is 64 points down the screen. You copy this frame and give the activity indicator that same frame. This would would if you were adding the activity indicator to a view whose y origin is at 0 points. Since the view you add it to is already 64 points down the screen, adding the activity indicator with that frame will make the activity indicators real y in terms of the phone screen 128 points down the screen. I got this number from adding the y origin of the view and the y origin of the activity indicator.

1

What I did to solve this problem is pushing the loading indicator on topmost controller:

private var topMostController: UIViewController? {
    var presentedVC = UIApplication.sharedApplication().keyWindow?.rootViewController
    while let pVC = presentedVC?.presentedViewController {
        presentedVC = pVC
    }

    return presentedVC
}

You might want to try this, a project of mine: https://github.com/goktugyil/EZLoadingActivity

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.