Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use pinch zoom(UIPinchGestureRecognizer) to change width of a UITextView?

I can get the UIPinchGestureRecognizer handler to work with scaling an object but I don't want to scale I want to change the size. For example I have a UITextView and I've attached a UIPinchGestureRecognizer gesture to it and if the user pinches I want to change the width of the textview to match the pinch. I don't want to scale it so the UITextView is larger(zooming).

like image 447
Ryan Detzel Avatar asked Apr 22 '10 13:04

Ryan Detzel


1 Answers

I am doing the very same thing. I will update this post if I found how to do it.

Try this, it work for me (for UIView):

- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender {
    static CGRect initialBounds;

    UIView *_view = sender.view;

    if (sender.state == UIGestureRecognizerStateBegan)
    {
        initialBounds = _view.bounds;
    }
    CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];

    CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
    _view.bounds = CGRectApplyAffineTransform(initialBounds, zt);
    return;
}
like image 104
oqu Avatar answered Sep 24 '22 16:09

oqu