美文网首页
TextView滚动至最后一行 跳动的bug解决

TextView滚动至最后一行 跳动的bug解决

作者: weirdyu | 来源:发表于2015-11-26 15:56 被阅读0次

    在使用UITextView的时候遇到一个bug,自动换行的时候会光标会不停的跳动,并且文字无法显示完全,最后找到解决方法:

    // 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];

    相关文章

      网友评论

          本文标题:TextView滚动至最后一行 跳动的bug解决

          本文链接:https://www.haomeiwen.com/subject/hprdhttx.html