iOS:通过捏缩放UITextView? [英] iOS: Scaling UITextView with pinching?

查看:97
本文介绍了iOS:通过捏缩放UITextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣创建 UITextView ,它在键入文本时动态扩展,并在用户捏住屏幕时进行缩放(可在TinyPost中找到相似的行为)。

I'm interested in creating UITextView that is expanding dynamically while typing the text, and scaling as the user pinches the screen(Similar behaviour can be found in TinyPost).

当你输入(没有捏)时,textView扩展正常。当你只是捏(没有打字)工作正常,但当你捏然后键入,里面的文字被削减。

When you just type (without pinching) the textView expands fine. When you just pinch (without typing) is works fine, but when you pinch and then type, the text inside gets cut.

这是我的代码:

UIPinchGestureRecognizer *pinchGestRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleTextView:)];
        pinchGestRecognizer.delegate = self;
        [bgFrameImageView addGestureRecognizer:pinchGestRecognizer];

    - (void)scaleTextView:(UIPinchGestureRecognizer *)pinchGestRecognizer{
        createTextView.transform = CGAffineTransformScale(createTextView.transform, pinchGestRecognizer.scale, pinchGestRecognizer.scale);

        pinchGestRecognizer.scale = 1;        
    }

    - (void)textViewDidChange:(UITextView *)textView{

        CGSize textSize = textView.contentSize;

        textView.frame = CGRectMake(CGRectGetMinX(textView.frame), CGRectGetMinY(textView.frame), textSize.width, textSize.height); //update the size of the textView  
    }

你怎么看?

推荐答案

尝试:

- (void)scaleTextView:(UIPinchGestureRecognizer *)pinchGestRecognizer{
     CGFloat scale = pinchGestRecognizer.scale;

    createTextView.font = [UIFont fontWithName:createTextView.font.fontName size:createTextView.font.pointSize*scale];

    [self textViewDidChange:createTextView];       
}

它基本上会缩放字体大小,然后使用您的代码重新计算内容大小textViewDidChange。

It basically scales the font size and then recalculates the content size using your code in textViewDidChange.

这篇关于iOS:通过捏缩放UITextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆