简体   繁体   中英

UITextView Scroll to Bottom, crop half of character

My app is message app and use UITextView to input word so that it could line break. The UITextView mechanism is when UITextView's height grows enough it will stop and auto-scroll. In the main.storyboard , I uncheck the Scrolling Enable. I therefore use setContentOffset (like below) to fulfill mechanism.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextViewTextDidChangeNotification object:nil];
}

-(void)textDidChange:(NSNotification *)note
{
    CGSize contentSizeInTextView = [_textView sizeThatFits:CGSizeMake(_textView.frame.size.width, MAXFLOAT)];
    if (contentSizeInTextView.height > _textView.frame.size.height) {
    CGPoint offset = CGPointMake(0, contentSizeInTextView.height - _textView.frame.size.height);
    [self.textView setContentOffset:offset animated:YES];
    }
} 

but when I run the code, it's cropping half of the word, because of the reputation of stackoverflow I can't post the image.

Could you tell what's I'm doing wrong?

There is many controller that you can use, SlackTextViewController is good option.

But there is other as well which you can use, Some of them are...
1. SlackTextViewController
2. whatsapp-ios
3. RDRStickyKeyboardView
4. AMMessageComposer
5. THSpringyCollectionView
6. Chats
7. ssmessagesviewcontroller

I will add more control in it in future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM