Reputation: 16825
I have a view, which the user can scale and rotate through UIGestureRecognizer
. This view contains two views:
superview
- content
- button
The content
should be scaled and rotated, and the button
should keep it's size and position.
I'am scaling and rotating the views with help of CGAffineTransform
and UIGestureRecognizer
.
How can I achieve this?
I've tried:
superview
and reset the button
transform and position. No success.content
and try to set the content.frame.size
to the superview
. No success. (Although I think this has to work somehow).Edit:
The code which handles the rotating and scaling:
if ([recognizer respondsToSelector:@selector(rotation)]) {
CGFloat rotation = 0.0f - (self.lastRotation - [(UIRotationGestureRecognizer *) recognizer rotation]);
CGAffineTransform currentTransform = self.content.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);
self.content.transform = newTransform;
self.lastRotation = [(UIRotationGestureRecognizer *) recognizer rotation];
} else if ([recognizer respondsToSelector:@selector(scale)]) {
CGFloat scale = 1.0f - (self.lastScale - [(UIPinchGestureRecognizer *) recognizer scale]);
CGAffineTransform currentTransform = self.content.transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
self.content.transform = newTransform;
self.lastScale = [(UIPinchGestureRecognizer *) recognizer scale];
}
Just basic scaling and rotating, nothing fancy.
Upvotes: 1
Views: 1140
Reputation: 16825
The actual solution:
if ([recognizer respondsToSelector:@selector(rotation)]) {
CGFloat rotation = 0.0f - (self.lastRotation - [(UIRotationGestureRecognizer *) recognizer rotation]);
CGAffineTransform currentTransform = self.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);
self.transform = newTransform;
self.lastRotation = [(UIRotationGestureRecognizer *) recognizer rotation];
} else if ([recognizer respondsToSelector:@selector(scale)]) {
CGFloat scale = 1.0f - (self.lastScale - [(UIPinchGestureRecognizer *) recognizer scale]);
CGRect bounds = self.bounds;
bounds.size.width *= scale;
bounds.size.height *= scale;
self.bounds = bounds;
self.lastScale = [(UIPinchGestureRecognizer *) recognizer scale];
}
Upvotes: 1