sale lanzamiento fecha descargar cuando iphone keyboard uitextfield

lanzamiento - ios 12 iphone 6s



iPhone-El teclado oculta TextField (12)

He hecho una aplicación simple para este problema. Verifica automáticamente la posición del campo de texto y si el teclado lo oculta, se moverá automáticamente según las necesidades.

- (void)textFieldDidBeginEditing:(UITextField *)textField { [self animateTextField:textField up:YES]; } - (void)textFieldDidEndEditing:(UITextField *)textField { [self animateTextField:textField up:NO]; } - (void) animateTextField: (UITextField*) textField up: (BOOL) up { int animatedDistance; int moveUpValue = textField.frame.origin.y+ textField.frame.size.height; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { animatedDistance = 216-(460-moveUpValue-5); } else { animatedDistance = 162-(320-moveUpValue-5); } if(animatedDistance>0) { const int movementDistance = animatedDistance; const float movementDuration = 0.3f; int movement = (up ? -movementDistance : movementDistance); [UIView beginAnimations: nil context: nil]; [UIView setAnimationBeginsFromCurrentState: YES]; [UIView setAnimationDuration: movementDuration]; self.view.frame = CGRectOffset(self.view.frame, 0, movement); [UIView commitAnimations]; } } -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }

Estoy utilizando UITextField para recibir entradas de usuario. Sin embargo, dado que mis campos de texto están hacia la mitad / parte inferior de la punta, se oculta cuando aparece el teclado. ¿Hay alguna forma de deslizarlo junto con el teclado para que esté en la parte superior del teclado durante la selección? Además, dado que también estoy usando el teclado numérico, ¿hay alguna manera fácil de incluir un botón hecho en alguna parte?

Gracias por la ayuda.


Esta situación es una mierda en el iPhone. Lo que se supone que debes hacer es diseñar tu interfaz de tal manera que los campos estén visibles cuando aparezca el teclado, o cambiar el campo cuando aparezca el teclado. (Y vuelve a bajar cuando termines)

Sugiero mirar algunas aplicaciones de Apple como Contactos o Configuraciones para ver cómo están lidiando con esto.

Además, estoy seguro de que el iPhone HIG tiene algo que decir al respecto.



El siguiente código funciona perfecto para mí.

[textFieldFocused becomeFirstResponder]; [self.view addSubview:startView]; [textFieldFocused resignFirstResponder];


Sé que llegué un poco tarde a responder esto, pero encontré una solución muy simple. Si usa un controlador UITableView en lugar de un UIViewController que tiene un tableView como objeto, este problema no aparece.

Cuando hace clic en el campo de texto que está en la parte inferior de la tabla, el teclado emerge y la vista de tabla se desplaza automáticamente hacia arriba hasta que el campo de texto que se está editando sea visible.

Sin embargo, el desplazamiento automático no funciona cuando utilizamos el botón de retorno en el teclado. En este escenario, hemos desplazado manualmente la tabla hacia arriba para ver el campo de texto.

espero que esto ayude


He estado buscando a través de innumerables respuestas a preguntas similares. Para aplicaciones básicas de pantalla única, esta solución funciona como un encanto y es increíblemente fácil de implementar: https://github.com/michaeltyson/TPKeyboardAvoiding

Ciertamente hay soluciones más elegantes, pero esto hará el trabajo rápido.


¡Es simple como configurar UITableView en modo edición!

- (void)viewDidLoad { [super viewDidLoad]; [self.tableView setEditing:YES]; }

Si desea ocultar un borrado de bubbels, a la izquierda de una celda, implemente un método UITableViewDelegate:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return NO; }


Usa este código:

- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // register for keyboard notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:self.view.window]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:self.view.window]; } - (void)viewDidDisappear:(BOOL)animated { // unregister for keyboard notifications while not visible. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil]; } - (void)keyboardDidHide:(NSNotification *)n { CGRect viewFrame = scrollView.frame; UIDeviceOrientation orientSide = [[UIDevice currentDevice] orientation]; if ((orientSide == UIDeviceOrientationLandscapeRight) || (orientSide == UIDeviceOrientationLandscapeLeft)) viewFrame.size.height += 140; else viewFrame.size.height += 216; //portrait mode scrollView.frame = viewFrame; keyboardVisible = NO; } - (void)keyboardDidShow:(NSNotification *)n { CGRect viewFrame = scrollView.frame; UIDeviceOrientation orientSide = [[UIDevice currentDevice] orientation]; if ((orientSide == UIDeviceOrientationLandscapeRight) || (orientSide == UIDeviceOrientationLandscapeLeft)) viewFrame.size.height -= 140; else viewFrame.size.height -= 216; //portrait mode scrollView.frame = viewFrame; keyboardVisible = YES; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { CGRect viewFrame = scrollView.frame; if ((interfaceOrientation == UIDeviceOrientationLandscapeRight) || (interfaceOrientation == UIDeviceOrientationLandscapeLeft)) //wants to change to landscape mode if (keyboardVisible == NO)//currently in portrait,check if keyboard was present viewFrame.size = CGSizeMake(480,250); else viewFrame.size = CGSizeMake(480,170); else {//wants to change to portrait mode if (keyboardVisible == NO)//currently in landscape,check if keyboard was present viewFrame.size = CGSizeMake(320,416); else viewFrame.size = CGSizeMake(320,200); } scrollView.frame = viewFrame; return YES; }

Funciona también para el modo horizontal, pero solo para iphone. Para iPad, cambie la configuración de cuadro en consecuencia. El método textFieldShouldReturn: hará que el teclado se oculte cuando se presiona return. Espero que esto ayude...


- (void)textFieldDidBeginEditing:(UITextField *)textField { NSLog(@"%f",textField.frame.origin.y); CGPoint scrollPoint = CGPointMake(0, textField.frame.origin); [scrollView setContentOffset:scrollPoint animated:YES]; } - (void)textFieldDidEndEditing:(UITextField *)textField { [scrollView setContentOffset:CGPointZero animated:YES]; }


- (void)textFieldDidBeginEditing:(UITextField *)textField { [self animateTextField:textField up:YES]; }

Utilice este código en su archivo view controller.m. Al usar este código al hacer clic en el campo de texto, aparecerá el teclado. Una vez que haga clic en su vista, el teclado se ocultará. Espero que esto lo ayude ...


si alguien lo necesita, he traducido la solución de ValayPatel de manera rápida

func animatedTextField(textField: UITextField, up: Bool){ var animatedDistance : Int = 0 let moveUpValue : Int = Int(textField.frame.origin.y) + Int(textField.frame.size.height) switch UIDevice.currentDevice().orientation { case .Portrait , .PortraitUpsideDown: animatedDistance = 216 - (460 - moveUpValue - 5) default: animatedDistance = 162 - (320 - moveUpValue - 5) } if (animatedDistance > 0 ){ let movementDistance : Int = animatedDistance let movementDuration : Float = 0.3 let movement = up ? -movementDistance : movementDistance UIView.beginAnimations(nil, context: nil) UIView.setAnimationBeginsFromCurrentState(true) UIView.setAnimationDuration(NSTimeInterval(movementDuration)) self.view.frame = CGRectOffset(self.view.frame, 0, CGFloat(movement)) UIView.commitAnimations() } }