Reputation:
I have a UIView
that I scale, pan and rotate with a UIButton
added to it as subview at (0,0)
with width and height of 50px
.
This button acts as a trigger for an editing functionality. The problem I'm having is that when I scale the UIView
using UIPinchGestureRecognizer
added to the UIView
such that it shrinks, I invert the transform on the UIButton
so that its size stays constant.
However due to the UIView
scale changing, it results in the UIButton
frame extending outside the parent UIView
. This renders part of the button unclickable. I would like to have the button stay within the parent UIView
, fixed at its origin at all times like when it was added, how do I go about doing this?
I've added the UIPinchGestureRecognizer
handler code below.
Thanks in advance.
- (void)scaleView:(UIPinchGestureRecognizer*)recognizer {
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
self.editBtn.transform = CGAffineTransformInvert(recognizer.view.transform);
recognizer.scale = 1;
}
Upvotes: 0
Views: 301
Reputation: 869
Your code is working just like as it should You defined the frame.origin for your UIButton (0,0) in its containing view and every time you scale the view it's frame changes.
CGAffineTransformInvert inverses the scale happened on the button but you need to change its origin in the containing view
Every time you scale your view it's frame changes and the button in the same place UIButton frame.origin is (0,0) and you never changed it
You can change the frame.origin of the UIButton every time you scale the containing view or you can put your UIButton outside the view you're trying to scale
Upvotes: 0