¡Ordenado! Simplemente utilizo una vista de texto 1x1px y utilizar el método delegado textViewDidChangeSelection:
EDIT: Para iOS 6 que tenía que cambiar la vista del texto a 50x50px (o al menos lo suficiente como para mostrar realmente el texto) para que esto funcione
También pude suprimir el teclado en pantalla cuando el pedal está desconectado.
Este es mi código en viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillDisappear:) name:UIKeyboardWillHideNotification object:nil];
UITextView *hiddenTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[hiddenTextView setHidden:YES];
hiddenTextView.text = @"aa";
hiddenTextView.delegate = self;
hiddenTextView.selectedRange = NSMakeRange(1, 0);
[self.view addSubview:hiddenTextView];
[hiddenTextView becomeFirstResponder];
if (keyboardShown)
[hiddenTextView resignFirstResponder];
keyboardShown
se declara como un bool
en mi archivo de cabecera.
A continuación, agregue estos métodos:
- (void)textViewDidChangeSelection:(UITextView *)textView {
/******TEXT FIELD CARET CHANGED******/
if (textView.selectedRange.location == 2) {
// End of text - down arrow pressed
textView.selectedRange = NSMakeRange(1, 0);
} else if (textView.selectedRange.location == 0) {
// Beginning of text - up arrow pressed
textView.selectedRange = NSMakeRange(1, 0);
}
// Check if text has changed and replace with original
if (![textView.text isEqualToString:@"aa"])
textView.text = @"aa";
}
- (void)keyboardWillAppear:(NSNotification *)aNotification {
keyboardShown = YES;
}
- (void)keyboardWillDisappear:(NSNotification *)aNotification {
keyboardShown = NO;
}
espero que este código ayuda a otra persona que está buscando una solución a este problema. Sientase libre de usarlo.
¿Funcionará con 'UIWebView'? – Dmitry
@Altaveron la propiedad keyCommands es una propiedad en UIResponder y UIWebView hereda de UIResponder, por lo que no veo ninguna razón por la que no funcione. – amergin
'UIWebView' es un contenedor para muchas subvistas. – Dmitry