El cursor UITextView no se posiciona correctamente al editar en iOS 7. ¿Por qué?


¿Por qué es esto una cosa que está sucediendo

Ese cuadro amarillo de arriba es un UITextView editable que se está editando actualmente (es el primer respondedor). Pero probablemente no se podía decir, ¿verdad? Porque no hay cursor. Pero la hay... Es ese pequeño punto azul en la parte inferior izquierda del TextView amarillo. Está ligeramente por debajo del borde inferior de TextViews. Así que si sigo yendo a una nueva línea, o presionando enter, el texto se moverá hacia arriba como debería naturalmente. Pero el cursor nunca está "nivelado", o justo encima de la parte inferior de UITextView frontera. Siempre apenas sale del fondo, un par de puntos por debajo de la frontera.

¿Por qué? Esto no fue un problema en iOS 6. ¿Alguna forma de arreglar esto?

Author: Joe, 2013-10-09

5 answers

Este error está en iOS 7.0 puede resolver esto modificando el método delegado TextView.

Intente debajo del código

- (void)textViewDidChange:(UITextView *)textView {
    CGRect line = [textView caretRectForPosition:
        textView.selectedTextRange.start];
    CGFloat overflow = line.origin.y + line.size.height
        - ( textView.contentOffset.y + textView.bounds.size.height
        - textView.contentInset.bottom - textView.contentInset.top );
    if ( overflow > 0 ) {
    // We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it)
    // Scroll caret to visible area
        CGPoint offset = textView.contentOffset;
        offset.y += overflow + 7; // leave 7 pixels margin
    // Cannot animate with setContentOffset:animated: or caret will not appear
        [UIView animateWithDuration:.2 animations:^{
            [textView setContentOffset:offset];
        }];
    }
}

Su problema será resuelto.

 41
Author: Pratik,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-10 14:06:09

Si estás en un escenario de controlador de navegación, creo que esto es en realidad el resultado de una propiedad que se introdujo en iOS 7: automaticallyAdjustsScrollViewInsets (ver guía de transición de iOS 7)

Esto por defecto es SÍ, y tratará de ser inteligente con el UITextView (que es en sí mismo una vista de desplazamiento) ajustando el desplazamiento de desplazamiento para la altura del controlador de navegación.

Por lo tanto, la solución es establecer esta propiedad en NO en su viewDidLoad (teniendo cuidado de no llamarla en iOS 6 ya que es solo disponible a partir de iOS 7).

 3
Author: chrishol,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-20 21:17:15

Basado en la respuesta que Todd dio, podría poner algo como esto en un método que se ejecuta cuando la aplicación termina de ejecutarse:

   [[UITextView appearance] setTintColor:[UIColor redColor]];
   [[UITextField appearance] setTintColor:[UIColor redColor]];

Esto afectará a todos los UITextFields y UITextViews.

 -1
Author: tavi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-25 11:32:27
- (BOOL) textView:(UITextView *)sender shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    NSString * newText = [sender.text stringByReplacingCharactersInRange:range withString:text];
    [self setFramesForText:newText];

    if (!IOS_VERSION_6_OR_LESS) {
        if ([text isEqualToString:@"\n"]){
            [textView setContentOffset:CGPointMake(textView.contentOffset.x, 999999999)];
        }
    }

    return YES;
}
 -1
Author: Aleksey Blokhin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-11 13:41:50

Solo necesita establecer el color Tint del UITextView.

Poner algo como lo siguiente en el código (lo puse en viewDidLoad) funcionó para mí.

self.textView.tintColor = [UIColor redColor];
 -3
Author: Todd,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-21 23:27:43