2012-05-05 20 views
6

Tengo una gran pantalla UITextView, casi a pantalla completa. Si toco, aparece el teclado y puedo editar el texto. Sin embargo, cuanto más escribo, eventualmente el texto se extiende por la vista, detrás del teclado. Ya no puedo ver lo que estoy escribiendo.UITextView, desplácese mientras edita?

¿Cómo lidiar con esto? ¿Tienes que rastrear la posición del cursor y desplazar la vista manualmente?

Respuesta

5

supongo que tiene que dimensione su UITextView como el teclado muestra/oculta. Entonces, el teclado no estará sobre tu vista de texto. Aquí están los códigos de muestra.

- (void)viewDidLoad 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillShow:) 
               name:UIKeyboardWillShowNotification 
               object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillHide:) 
               name:UIKeyboardWillHideNotification 
               object:nil]; 
} 

- (void)keyboardWillShow:(NSNotification *)notification 
{ 
    [UIView beginAnimations:nil context:nil]; 
    CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
    CGRect newRect = YOUT_TEXT_VIEW.frame; 
    //Down size your text view 
    newRect.size.height -= endRect.size.height; 
    YOUT_TEXT_VIEW.frame = newRect; 
    [UIView commitAnimations]; 
} 

- (void)keyboardWillHide:(NSNotification *)notification 
{ 
    ... // Resize your textview when keyboard is going to hide 
} 
+0

Gracias Querido Thant Thet. – jamil

7

Es necesario utilizar siguiente código para el desplazamiento hacia abajo TextView según diagrama de texto (o dicen de acuerdo con la tipificación)

NSRange range = NSMakeRange(textView.text.length - 1, 1); 
[textView scrollRangeToVisible:range]; 

Esperanza, esto le ayudará a ...

+0

Gracias por la respuesta ... pero obtuve el enlace que quiero hacer ... Más adelante, el enlace funciona bien. – jamil

+3

https://developer.apple.com/library/ios/#samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html – jamil

+3

@ user1328096 Para la posteridad, ¿puede escribir la solución a su pregunta como una respuesta correcta? (¡Y no olvides aceptar algunas respuestas!) –

Cuestiones relacionadas