Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common ancestor constraints issue. This is how I solved it. #9

Open
keegho opened this issue Sep 28, 2020 · 0 comments
Open

Common ancestor constraints issue. This is how I solved it. #9

keegho opened this issue Sep 28, 2020 · 0 comments

Comments

@keegho
Copy link

keegho commented Sep 28, 2020

ERROR:

"Because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies?"

Change the topView to a dynamic one. When user uses showProgressView function he has to pass by self.view

   `open func showProgressView(_ ancestorView: UIView) {
    
    //This is making an error
   //guard let topView = UIApplication.shared.keyWindow?.rootViewController?.view else {
   //return
   //}
    
    containerView.backgroundColor = self.backgroundColor
    progressView.backgroundColor = self.forgroundColor
    activityIndicator.style = self.activityStyle

    UIApplication.shared.keyWindow?.addSubview(containerView)
    progressView.addSubview(activityIndicator)
    containerView.addSubview(progressView)
    
    activeConstraints = [
        containerView.heightAnchor.constraint(equalTo: ancestorView.heightAnchor),
        containerView.widthAnchor.constraint(equalTo: ancestorView.widthAnchor),
        containerView.leadingAnchor.constraint(equalTo: ancestorView.leadingAnchor),
        containerView.topAnchor.constraint(equalTo: ancestorView.topAnchor),

        progressView.heightAnchor.constraint(equalToConstant: self.size.height),
        progressView.widthAnchor.constraint(equalToConstant: self.size.width),
        progressView.centerYAnchor.constraint(equalTo: containerView.centerYAnchor),
        progressView.centerXAnchor.constraint(equalTo: containerView.centerXAnchor),

        activityIndicator.heightAnchor.constraint(equalToConstant: self.size.height),
        activityIndicator.widthAnchor.constraint(equalToConstant: self.size.width),
        activityIndicator.centerYAnchor.constraint(equalTo: progressView.centerYAnchor),
        activityIndicator.centerXAnchor.constraint(equalTo: progressView.centerXAnchor)
    ]
    
    
    for constraint in activeConstraints {
        constraint.isActive = true
    }

    activityIndicator.startAnimating()

}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant