当用户开始滚动或点击textview时,如何立即设置textView的Scrollview的内容大小 [英] how set content size of textView's Scrollview immediately when user starts scrolling or when tap on textview

查看:39
本文介绍了当用户开始滚动或点击textview时,如何立即设置textView的Scrollview的内容大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在包含图像/( UIImageView )中有 UITextView .

I have UITextView in that in include image/ (UIImageView ).

但是当我想查看图像时,无法看到/滚动

But when i want to see the image it is unable to see / scroll,

i实现了逻辑,以根据文本大小动态增加滚动内容大小,

i implemented logic to increase the scroll content size dynamically with respective to the text size,

- (void)scrollViewDidScroll:(UIScrollView *)scrollview 
{
      if (scrollview.contentOffset.y >= scrollview.contentSize.height - scrollview.frame.size.height) 
      {

            CGSize s = [messageView.text sizeWithFont:[UIFont systemFontOfSize:25] //define your textview font size
                                    constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  // - 40 For cell padding
                                        lineBreakMode:UILineBreakModeWordWrap];   

            // To increase the text view scroll content to display image also
            [scrollview setContentSize:CGSizeMake(200, s.height+150)];

      }       
}

,但是仅当文本视图中的文本超出其(textview)范围时,它才开始滚动.

but it starts scrolling only when text in the text view exceeds its (textview) bounds.

如果文本在边界内(在文本视图中没有行可以容纳),我无法查看完整图像

I was unable to see the full image if the text is with in bounds (no of lines can fit in text view)

如何在触摸/开始在textview上滚动时设置滚动大小

How to set scroll size when touch / starts scrolling on textview,,

推荐答案

在将文本设置为messageView( UITextView )

use this code after set the text to the messageView(UITextView)

    messageView.frame = CGRectMake(messageView.frame.origin.x, messageView.frame.origin.y, messageView.frame.size.width, messageView.contentSize.height + 150);
    float fscrview = messageView.frame.origin.y + messageView.frame.size.height + 150;
    scrollview.contentSize=CGSizeMake(320, fscrview);

这篇关于当用户开始滚动或点击textview时,如何立即设置textView的Scrollview的内容大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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