I have a UIImageView (and a UITextView) and I am changing the hight and with of them both using a plus and minus button. However I wanted to do like you can do in most programs, where a box appears round my views, and the user can drag a corner of it to resize. Only one corner needs to be dragged. The opposite is fixed. How do you do this?
Asked
Active
Viewed 536 times
2 Answers
2
Another way - is by GestureRecognizer. In some task i resized image like this:
- (void)resizeImage:(UIPinchGestureRecognizer *)recognizer
{
if ([recognizer state] == UIGestureRecognizerStateBegan)
previousScale = [recognizer scale];
UIView *viewToResize = recognizer.view;
if ([recognizer state] == UIGestureRecognizerStateChanged)
{
CGFloat currentScale = [[viewToResize.layer valueForKeyPath:@"transform.scale"] floatValue];
CGFloat newScale = 1 - (previousScale - [recognizer scale]);
newScale = MIN(newScale, MAX_SCALE / currentScale);
newScale = MAX(newScale, MIN_SCALE / currentScale);
CGAffineTransform transform = CGAffineTransformScale([viewToResize transform], newScale, newScale);
viewToResize.transform = transform;
previousScale = [recognizer scale];
}
}

Oleshko
- 2,923
- 4
- 17
- 25
-
Im reading that this is the better way of completing the task now. You can resize the view with a lot less code than using touchesBegan and touchesEnded – Esko918 May 16 '14 at 18:11
-
Yes, it's easier way :) If you have some question about this code - fell free to ask. – Oleshko May 19 '14 at 08:12
-1
I never done this before but i think you would have to override the touchesBegan and touchesMoved functions of the view. When you initiate the touchesBegan method make sure you are touching the correct view, (Imageview or UItextView) set a boolen in their stating. imTouchingOneOrTheOther. So when you now hit the touchesMoved function you can adjust the size of the frame accordingly. I would try to adjust the frame first with UIView block based animations and if that doesn't look ok then i would play around with coreAnimation. Let me know how it works out.

Esko918
- 1,397
- 1
- 12
- 25
-
-
Yes but instead of adjusting the frame use the bounds. Bounds should be the correct property you should be adjusting. – Esko918 May 16 '14 at 15:50
-
-
Here with a little googling I found this post that explains exactly. http://stackoverflow.com/questions/8460119/how-to-resize-uiview-by-dragging-from-its-edges – Esko918 May 16 '14 at 15:56
-
So now whomever gave me a negative on my answer id appreciate making it a plus – Esko918 May 16 '14 at 15:57