如何使用捏缩放(UIPinchGestureRecognizer)来改变UITextView的宽度? [英] How can I use pinch zoom(UIPinchGestureRecognizer) to change width of a UITextView?
问题描述
我可以使用 UIPinchGestureRecognizer
处理程序来处理扩展对象,但我不想扩展我想要更改大小。例如,我有一个 UITextView
,我已经附加了一个 UIPinchGestureRecognizer
手势,如果用户捏我想要更改textview的宽度以匹配夹点。我不想缩放它,所以 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).
推荐答案
我正在做同样的事情。
如果我发现如何做,我会更新这篇文章。
I am doing the very same thing. I will update this post if I found how to do it.
试试这个,它对我有用(对于UIView):
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;
}
这篇关于如何使用捏缩放(UIPinchGestureRecognizer)来改变UITextView的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!