久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ios - 如何在 UITextView 中找到可見的文本范圍?

ios - how to find what is the visible range of text in UITextView?(ios - 如何在 UITextView 中找到可見的文本范圍?)
本文介紹了ios - 如何在 UITextView 中找到可見的文本范圍?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何在可滾動、不可食用的 UITextView 中找到可見的文本?

how to find what text is visible in a scrollable, non-ediable UITextView?

例如我可能需要顯示下一段,然后我想找到當前可見的文本范圍并使用它來計算適當的范圍并使用 scrollRangeToVisible: 滾動文本視圖

for example i may need to show next paragraph, then i want to find the current visible text range and use it to calculate the appropriate range and use scrollRangeToVisible: to scroll the text view

推薦答案

我這樣做的方法是計算每個段落的所有大小.用 sizeWithFont:constrainedToSize:lineBreakMode:

The way i would do it is to compute all the sizes of each paragraph. With sizeWithFont:constrainedToSize:lineBreakMode:

然后,您將能夠從 [textView contentOffset] 確定哪個段落是可見的.

you will then be able to work out which paragraph is visible, from the [textView contentOffset].

要滾動,不要使用 scrollRangeToVisible,只需使用 setContentOffset:CGPoint y 參數應該是下一段的所有高度大小的總和,或者只是添加 textView.frame.size.height,如果是的話比下一段的開頭更接近.

to scroll, dont use scrollRangeToVisible, just use setContentOffset: The CGPoint y parameter for this should either be the sum of all the height sizes to the next paragraph, or just add the textView.frame.size.height, if that is closer than the beginning of the next paragraph.

這有意義嗎?

回答下面的評論請求代碼(未經測試):

in answer to comment requst code bellow (untested):

  CGFloat paragraphOffset[MAX_PARAGRAPHS];

    CGSize constraint = CGSizeMake(widthOfTextView, 999999 /*arbitrarily large number*/);
    NSInteger paragraphNo = 0;
    CGFloat offset = 0;

    for (NSString* paragraph in paragraphs) {
        paragraphOffset[paragraphNo++] = offset;
        CGSize paragraphSize = [paragraph sizeWithFont:textView.font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
        offset += paragraphSize.height;
    }   

    // find visible paragraph
    NSInteger visibleParagraph = 0;
    while (paragraphOffset[visibleParagraph++] < textView.contentOffset.y);


    // scroll to paragraph 6
    [textView setContentOffset:CGPointMake(0, paragraphOffset[6]) animated:YES];

這篇關于ios - 如何在 UITextView 中找到可見的文本范圍?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 成人在线视频免费观看 | 国产精品久久久久免费 | 久久国产精品-国产精品 | 色视频一区二区 | www.亚洲| 亚洲a视 | 五月婷婷在线播放 | 在线免费观看视频黄 | 五月免费视频 | 成人高清在线 | 天堂久久天堂综合色 | 欧美在线观看一区 | 国产精品中文字幕在线观看 | 国产欧美日韩精品在线观看 | 网色| 中国av在线免费观看 | 国产精品免费观看 | 国产麻豆一区二区三区 | 午夜影院操| 欧美aaa一级片 | 久久精品亚洲欧美日韩久久 | 国产精品一卡二卡三卡 | 午夜精品久久久久久不卡欧美一级 | 亚洲欧美激情精品一区二区 | 一区影视 | 91亚洲一区 | 日韩午夜网站 | 国产精品高潮呻吟久久av黑人 | 一本一道久久a久久精品综合蜜臀 | 户外露出一区二区三区 | 一区二区三区av夏目彩春 | 精品免费看 | 91黄色片免费看 | 日日干夜夜干 | www操操| 欧美精品影院 | 亚洲国产日韩欧美 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 日韩欧美在线视频观看 | 免费在线a视频 | 龙珠z在线观看 |