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

后端 未结 4 1568
陌清茗
陌清茗 2020-12-25 09:52

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

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 10:28

    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;
    }
    

提交回复
热议问题