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

在 iOS 7 中滾動到 UITextView 不穩定的底部

Scroll to bottom of UITextView erratic in iOS 7(在 iOS 7 中滾動到 UITextView 不穩定的底部)
本文介紹了在 iOS 7 中滾動到 UITextView 不穩定的底部的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

以下代碼在 iOS 中可以正常工作

7.0.在 iOS 7 中,當 UITextView 更新時,滾動會斷斷續續且不穩定.我不確定這是否是 iOS 7 中的錯誤,或者我做錯了什么.

The following code will work fine in iOS < 7.0. In iOS 7 the scrolling will be choppy and erratic while the UITextView is updating. I'm not sure if this is a bug in iOS 7, or I am doing something wrong.

TestController.h

//TODO: Add UITextView in storyboard and tie to textView outlet

#define MAX_TEXT_VIEW_CHARACTERS 1000
@interface TestController : UIViewController  {
    NSMutableString *_outputText;
    NSTimer *_outputTimer;
}

@property (strong, nonatomic) IBOutlet UITextView *textView;

@end

TestController.m

@implementation TestController
@synthesize textView;

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _outputText = [NSMutableString stringWithCapacity:MAX_TEXT_VIEW_CHARACTERS];
    _outputTimer =  [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(outputLine:) userInfo:nil repeats:YES];
}

-(void)outputLine:(NSTimer *) theTimer {
    static int i = 0;
    //Run this 100 times
    if (i > 99) {
        [_outputTimer invalidate];
        return;
    }
    [self outputToScreen:[NSString stringWithFormat:@"Some string %d
", ++i]];
}

-(void)outputToScreen:(NSString *)str {
    if (!str || !str.length) return;  //Nothing to output

    NSInteger outputTextSize = _outputText.length;
    [_outputText appendString:str];
    if (outputTextSize > MAX_TEXT_VIEW_CHARACTERS)
        [_outputText deleteCharactersInRange:NSMakeRange(0, outputTextSize - MAX_TEXT_VIEW_CHARACTERS)];
    self.textView.text = _outputText;

    [self scrollOutputToBottom];
}

-(void)scrollOutputToBottom {
    CGPoint p = [textView contentOffset];
    [textView setContentOffset:p animated:NO];
    [textView scrollRangeToVisible:NSMakeRange([textView.text length], 0)];
}

@end

推薦答案

這顯然是 iOS 7 的 bug.這是一個解決方法,直到蘋果修復它.解決方法基本上是通過從頭開始創建 NSTextStorageNSLayoutManager 來實例化 UITextView.蘋果一定是忘記在 UITextView 初始化方法中進行初始化了.我提交了錯誤報告,希望你也這樣做.

This is obviously an iOS 7 bug. Here is a workaround until apple fixes it. The workaround is basically instantiates a UITextView by creating an NSTextStorage and NSLayoutManager from scratch. Apple must have forgotten to initialize something in UITextView initialization method. I filed a bug report and I hope you do too.

// ios7 bug fix
// check if the device is running iOS 7.0 or later
NSString *reqSysVer = @"7.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer  options:NSNumericSearch] != NSOrderedAscending);

if (osVersionSupported) {
    NSTextStorage* textStorage = [[NSTextStorage alloc] init];
    NSLayoutManager* layoutManager = [NSLayoutManager new];
    [textStorage addLayoutManager:layoutManager];
    NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:self.view.bounds.size];
    [layoutManager addTextContainer:textContainer];
    yourTextView = [[UITextView alloc] initWithFrame:someFrameForYourTextView
                                       textContainer:textContainer];
    // if using ARC, remove these 3 lines
    [textContainer release];
    [layoutManager release];
    [textStorage release];
}
else {
    yourTextView = [[UITextView alloc] initWithFrame:someFrameForYourTextView];
}

這篇關于在 iOS 7 中滾動到 UITextView 不穩定的底部的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 一区二区在线免费观看 | 久久亚洲精品久久国产一区二区 | 欧美jizzhd精品欧美巨大免费 | 国产精品一区二区视频 | 蜜桃精品视频在线 | 亚洲a级| 午夜丰满少妇一级毛片 | 国产欧美一区二区三区在线看 | 国产精品一区二区无线 | 啪啪网页 | 亚洲精品一区二区三区丝袜 | 色综合色综合色综合 | 国产精品欧美一区二区三区 | 交专区videossex农村 | 在线免费观看黄网 | 久久久精品一区二区三区 | 亚洲一区二区三区在线 | 中文字幕av免费 | 国产精品欧美一区二区 | 欧美日韩成人影院 | 亚洲一区二区三区在线播放 | 免费国产精品久久久久久 | 成年人黄色一级片 | 欧洲色综合 | av片在线观看网站 | 国内精品视频在线 | 国产一区免费视频 | 一道本一区二区 | 中文成人在线 | 99热.com| 亚洲视频在线看 | 欧美激情在线精品一区二区三区 | 国产视频精品在线 | 一级a爱片久久毛片 | 欧美成人精品一区二区男人看 | 欧美网站一区二区 | 亚洲国产精品久久久久秋霞不卡 | 精品1区2区3区 | 爱爱视频网 | 亚洲三级在线 | 视频1区2区 |