iphone – 如何使用捏缩放(UIPinchGestureRecognizer)来改变UITextView的宽度?

语言: CN / TW / HK

我可以让UIPinchGestureRecognizer处理程序使用缩放对象,但我不想扩展我想改变大小.例如,我有一个UITextView,我已经附加了一个UIPinchGestureRecognizer手势,如果用户捏,我想改变textview的宽度以匹配捏.我不想缩放它,所以UITextView更大(缩放).

我正在做同样的事情.

如果我发现如何做,我会更新这篇文章.

试试这个,它对我有用(对于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;
}

翻译自:https://stackoverflow.com/questions/2691369/how-can-i-use-pinch-zoomuipinchgesturerecognizer-to-change-width-of-a-uitextvi

分享到: