Ho un UITextView
che in iOS 7 si comporta correttamente. In iOS 8 si comporta in modo strano.Comportamento UITextView inset iOS 7 vs iOS 8
Quando inserisco del testo che diventa due righe, aggiorno la dimensione di inputView, che contiene la vista testo. Aggiorno anche la dimensione del textview ma in qualche modo sembra scorrere la prima riga; eppure questo non si riflette nelle sue dimensioni.
video per il comportamento in iOS 7 (corretto): https://www.dropbox.com/s/rr4pea6wudobmk8/iOS7.mov
video per il comportamento in iOS 8: https://www.dropbox.com/s/iyqrsp41uz5mn85/iOS8.mov
ho impostato [self setAutomaticallyAdjustsScrollViewInsets:NO];
, ma nessun cambiamento. Questo non mi ha aiutato: What is Causing this Unwanted Content Inset with UITextView in iOS 8 (not there in iOS 7)?
Ci sono i risultati del mio NSLog
in iOS 8:
2014-12-22 02:02:48.104 Date For Date[68577:10129965] DID BEGIN: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:50.579 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:50.768 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:50.960 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:51.168 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:52.145 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:52.408 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
Questo è il mio codice:
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[textView becomeFirstResponder];
if(!self.previousTextViewContentHeight)
self.previousTextViewContentHeight = textView.contentSize.height;
[self _scrollToBottom:YES];
NSLog(@"DID BEGIN: textContainerInset Top: %f - contentInset Bottom: %f - scrollIndicatorInset: %f", textView.textContainerInset.top, textView.contentInset.top, textView.scrollIndicatorInsets.top);
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
[textView resignFirstResponder];
}
- (void)textViewDidChange:(UITextView *)textView
{
// Textfield
NSLog(@"DID CHANGE: textContainerInset Top: %f - contentInset Bottom: %f - scrollIndicatorInset: %f", textView.textContainerInset.top, textView.contentInset.top, textView.scrollIndicatorInsets.top);
CGFloat maxHeight = [JSMessageInputView maxHeight];
CGFloat textViewContentHeight = MIN(textView.contentSize.height, maxHeight);
CGFloat changeInHeight = textViewContentHeight - self.previousTextViewContentHeight;
self.previousTextViewContentHeight = MIN(textViewContentHeight, maxHeight);
if(changeInHeight != 0.0f) {
textView.frame = CGRectMake(6, 3, textView.frame.size.width, textView.frame.size.height + changeInHeight);
textView.contentInset = UIEdgeInsetsMake(0.0f,
0.0f,
0.0f,
0.0f);
[textView setContentSize:CGSizeMake(textView.contentSize.width, textView.contentSize.height + changeInHeight)];
// Change table
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0.0f, self.bubbleTable.contentInset.bottom + changeInHeight, 0.0f);
self.bubbleTable.contentInset = insets;
self.bubbleTable.scrollIndicatorInsets = insets;
[self _scrollToBottom:YES];
// Change input view
CGRect inputViewFrame = self.inputView.frame;
self.inputView.frame = CGRectMake(0.0f,
inputViewFrame.origin.y - changeInHeight,
inputViewFrame.size.width,
inputViewFrame.size.height + changeInHeight);
}
self.inputView.sendButton.enabled = ([textView.text trimWhitespace].length > 0);
}
Che cosa sto facendo di sbagliato?
Allegare un progetto di esempio. –
Non ne ho ancora uno per te, appena trovo il tempo ... Ne farò uno. Spiacente :( –
Hai una taglia aperta. Mi piacerebbe aiutare. –