UITextView in iOS7 clips the last line of text string

后端 未结 11 1291
轻奢々
轻奢々 2020-12-04 09:30

UITextView in iOS7 has been really weird. As you type and are entering the last line of your UITextView, the scroll view doesn\'t scroll to the bottom like it should and it

11条回答
  •  清歌不尽
    2020-12-04 09:46

    Set theViewDelegate to "self" in your .m and use in your .h then add this code to your .m

    Will handle BOTH the versions of this glitch that are occurring for going to the next line with text (wrapping or carriage return) and typing... AND going to the next line with just a carriage return and no typing (this code, unlike other's code, will scroll to show the blinking cursor not being clipped in this second glitch scenario)

    //!!!*!!****!*!**!*!*!!!MAKE SURE YOU SET DELEGATE AND USE THE 
    
    -(void)textViewDidChange:(UITextView *)textView {
        [theTextView scrollRangeToVisible:[textView selectedRange]];//resizing textView frame causes text itself "content frame?" to still go below the textview frame and get clipped... auto-scrolling must be implimented. (iOS7 bug)
    }
    
    -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
        if (([text isEqualToString:@"\n"]) && (range.location == textView.text.length)) {//"return" at end of textView
            [textView scrollRectToVisible:CGRectMake(5,5,5,999999999999999999) animated:NO];//for some reason the textViewDidChange auto scrolling doesnt work with a carriage return at the end of your textView... so I manually set it INSANELY low (NOT ANIMATED) here so that it automagically bounces back to the proper position before interface refreshes when textViewDidChange is called after this.
        }
        return YES;
    }
    

提交回复
热议问题