Reputation: 1925
I have a UIView
added as a subview inside its parent view. When the user taps on this UIView
, I want it to be transformed so it takes the entire screen.
I am trying to do so by changing its transform
property and I was able to make its size match its parent view but not its position.
I read the Apple documentation and found frame
cannot be used with transform
. How do I make its position line up with its parent view?
Also, without using transform
, is it a good idea to do so by changing its constraints, e.g., NSLayoutAttributeHeight
?
Upvotes: 0
Views: 1819
Reputation: 3940
i think you can simply change the frame after you scale it by transform like this:
//i am using 5 for testing purpose
self.backgroundImageView.transform = CGAffineTransformMakeScale(5, 5);
self.backgroundImageView.frame = CGRectMake(0, 0, self.backgroundImageView.frame.size.width, self.backgroundImageView.frame.size.height);
OR change the anchor point before the scale:
self.backgroundImageView.layer.anchorPoint = CGPointMake(0.5, 0.5);
self.backgroundImageView.transform = CGAffineTransformMakeScale(5, 5);
Update: if you use Autolayout in your UIView, the solution might depends on how you set up your constraints, For example, if you set up your image constraints like this:
I would suggest still using the scale transform, but change the top and left constraint to 0.
or you set up your image constraint like this:
I would change the center alignment x and y to the center point of the super view
Maybe you can let me know how you set up you constraints, i can do some test for you on my local.
Upvotes: 1