0

I have a highlightView which I would like to constraint to another view. This is my function for it:

func showHighlightView(viewToHighlight: UIView, height: CGFloat) {
    self.view.addSubview(highlightView)
    highlightView.heightAnchor.constraint(equalTo: viewToHighlight.heightAnchor).isActive = true
    highlightView.widthAnchor.constraint(equalTo: highlightView.heightAnchor).isActive = true
    
    highlightView.centerXAnchor.constraint(equalTo: viewToHighlight.centerXAnchor).isActive = true
    highlightView.centerYAnchor.constraint(equalTo: viewToHighlight.centerYAnchor).isActive = true
    highlightView.layer.cornerRadius = height/2

    highlightView.layer.add(self.scaleAnimation, forKey: "scale")

    self.view.bringSubviewToFront(viewToHighlight)
}

This is working for most of my cases. However I have one view which I transform like this:

var transformerBumbleBee = CGAffineTransform.identity
transformerBumbleBee = transformerBumbleBee.translatedBy(x: 25, y: -80)
transformerBumbleBee = transformerBumbleBee.scaledBy(x: 1, y: 1)
self.addListButton.transform = transformerBumbleBee

with this addListButton my showHightLightView() is constraining to the identity-constraint of addListButton and not the transformed. Is there a way to change that?

2 Answers 2

1

transform doesn't apply constraints to other views , you need to make translate and scale actions with changing the constraints's constants/multipliers values

Sign up to request clarification or add additional context in comments.

Comments

0

Transformations can not be used along with constraints, probably you may receive some runtime warnings related to constraints if you use the code above.

Use either of the way, just add view as subview programatically in view and apply transformations.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.