NVActivityIndicatorView: Aligning problem on XCode 8

I’m having trouble to align the indicator view on storyboard. I have a basic app and single view controller. Indicator is located to the center of view and it spins until the page contents load from the server. However, when I hit the run button, loading indicator is spinning in the right corner of the view, overflowing and not aligning to the center itself.

Scenario can be replicated by following steps:

  • Add a UIView to a UIViewController on storyboard.
  • Add static height and width and contraints (let say 100,100)
  • Align center vertically and horizontally
  • Change the class of UIView to NVActivityIndicatorView
  • Assign activity type and color.
  • Hit the run button.

I’m building with XCode 8 and Swift 3.0. Is there any way to fix this?

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Creating an instance of NVActivityIndicatorView and aligning programmatically always works as you stated in your example. However, storyboard problem still exists.

class TestViewController: UIViewController {

    private var activityView: NVActivityIndicatorView!

    override func viewDidLoad() {
        super.viewDidLoad()
        showLoadingIndicator()
    }

    func showLoadingIndicator(){
        if activityView == nil{
            activityView = NVActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 100.0, height: 100.0), type: NVActivityIndicatorType.ballClipRotate, color: UIColor.black, padding: 0.0)
            // add subview
            view.addSubview(activityView)
            // autoresizing mask
            activityView.translatesAutoresizingMaskIntoConstraints = false
            // constraints
            view.addConstraint(NSLayoutConstraint(item: activityView, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0))
            view.addConstraint(NSLayoutConstraint(item: activityView, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0))
        }

        activityView.startAnimating()
    }

    func stopLoadingIndicator(){
        activityView.stopAnimating()
    }
}

This has been fixed in Xcode 8.1 🎉.

If this still actual issue for someone, I fixed it by calling updateConstraints and layoutIfNeeded before start animations.

I think this is mostly bug in Xcode 8. Workaround may be needed in the meantime waiting for Xcode update.

Constant 1000x1000 size suggests the idea that interface object is not properly decoded by Xcode 8. Probably width/height replaced by value of some constraint priority (@ 1000).