I have a UIImageView
, and a series of conflicting constraints set on it.
I set the active
property of some of them to true
or to false
at different times, and it works—the image view is always where it's supposed to be.
However, in another method, I use it's frame to calculate the position of another view, and so I noticed that it's frame isn't where the image view appears. For example, the image view appears centered in the middle of the screen, but it's frame (I created another UIView and set it's frame to the image view's frame to test this), is in the bottom left—where the image view used to be before changing which constraints were active.
Is there a way I can update the frame so that it reflects where the image view actually is? Or, is there a way to get the true frame of the image view?
Here's the code (qrCode
is the view I'm trying to arrange, myContainer
is its superview):
self.qrCode.setTranslatesAutoresizingMaskIntoConstraints(false)
//this sets qrCode 0 pts from the bottom of its parent
self.bottom.active = false
//this centers qrCode vertically in its parent
self.center.active = true
//these set how far the parent is from the edges of its view
self.newLeft.active = true
self.newRight.active = true
let testView = UIView(frame: qrCode.frame)
testView.backgroundColor = UIColor.greenColor()
self.myContainer.addSubview(testView)
All this code positions the image view (qrCode
) correctly, but it's frame (as shown by testView
is in the wrong location—it's where qrCode was before the constraints were configured.