简体   繁体   English

第二次点击(有时)后出现文本框键盘

[英]Keyboard for textfield appears after second tap (time to time)

I have one view in my app where there is 1 text field. 我的应用程序中只有一个视图,其中有1个文本字段。 And I've noticed that keyboard appears after second tap. 而且我注意到第二次点击后出现了键盘。

But it's interesting that on iPhone it's time to time (some time appears after first tap at once, and some time after second tap only). 但是有趣的是,在iPhone上是不定时的(一次单击后会出现一段时间,而第二次单击后会出现一段时间)。 On iPad looks like it more ofter appears after second tap only. 在iPad上,看起来似乎只有第二次点击才出现。

  • I use UITextFieldDelegate 我使用UITextFieldDelegate

  • in viewDidLoad I assign the delegate _locationTextField.delegate = self; viewDidLoad我分配委托_locationTextField.delegate = self;

  • and I use delegate methods textFieldDidBeginEditing , textFieldDidEndEditing , textFieldShouldReturn 我使用委托方法textFieldDidBeginEditingtextFieldDidEndEditingtextFieldShouldReturn

eg: 例如:

#pragma mark -
#pragma mark UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    _locationNameBeforeManualEdit = _locationTextField.text;
    // save the previod city value to compare after did end editing
    NSLog(@"textFieldDidBeginEditing");

}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    NSLog(@"textFieldDidEndEditing");

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self continueButtonPressed:nil];
    // [textField resignFirstResponder];
    return YES;
}

in storyboard 在故事板中 在此处输入图片说明

What could be the problem? 可能是什么问题呢?

Found solution here on Stackoverflow - solution related with keyboard preload: 在Stackoverflow上找到了解决方案-与键盘预加载有关的解决方案:

- (void)preloadKeyboard {
    UITextField *lagFreeField = [[UITextField alloc] init];
    [self.window addSubview:lagFreeField];
    [lagFreeField becomeFirstResponder];
    [lagFreeField resignFirstResponder];
    [lagFreeField removeFromSuperview]; 
}

This method should be used in application: didFinishLaunchingWithOptions: method of AppDelegate . 此方法应该在使用application: didFinishLaunchingWithOptions:的方法AppDelegate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 键盘第二次不辞职? - Keyboard not resigning second time? 每次敲击键盘后如何获取文本字段的文本(Swift iOS) - How to get the text of a textfield after every tap on a keyboard (Swift iOS) 当我第二次点击时,UISearchBar消失 - UISearchBar disappears when I tap second time 在关闭LoginViewController后第二次点击登录按钮时,Spotify EXC_BAD_EXE - Spotify EXC_BAD_EXE while second time tap on Login Button after dismiss LoginViewController 每次我重新点击文本字段时,视图都会发生变化 - View is getting shifted every time I re-tap textfield iOS Amplify 查询仅在第二次出现视图控制器后才有效 - iOS Amplify queries only work after second time view controller appears 设置日期后,还要在文本字段上设置时间 - Set time also on a textfield after setting the date UIAlertController出现后会自动关闭一部分时间 - UIAlertController automatically closes fraction of time after it appears 如何存储我的第一个文本字段以免第二次快速查询 - How to store my first textfield to not ask for the second time in swift 滚动视图内的文本字段仅在键盘出现IOS之后向上移动 - Textfield inside a scroll view only moves up after keyboard appears IOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM