在ios 11中,becomeFirstResponder不显示键盘

在ios 11中,becomeFirstResponder不显示键盘,第1张

概述我尝试在加载屏幕后显示键盘,如下所示: -(void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)]; tf.borderS 我尝试在加载屏幕后显示键盘,如下所示:

-(voID) vIEwDIDAppear:(BOol)animated {     [super vIEwDIDAppear:animated];     UITextFIEld *tf = [[UITextFIEld alloc] initWithFrame:CGRectMake(10,200,300,40)];     tf.borderStyle = UITextborderStyleRoundedRect;     tf.text = @"test";    [self.vIEw addSubvIEw:tf];     if([tf canBecomeFirstResponder]){        [tf becomeFirstResponder]; // surely this line is called               } }

此代码适用于ios 8,9,10但不适用11.我不确定为什么键盘不会在ios 11上自动显示,而文本字段正在聚焦(有光标).
在这种情况下,不会调用键盘的通知:

[[NSNotificationCenter defaultCenter] addobserver:self                                         selector:@selector(keyboarDWillShow:)                                             name:UIKeyboarDWillShowNotification                                           object:nil];- (voID) keyboarDWillShow:(NSNotification *)note {    NSDictionary *userInfo = [note userInfo];    CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;    DLog(@"Keyboard Height: %f WIDth: %f",kbSize.height,kbSize.wIDth); }

我甚至试过这个:

[tf performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];

但仍然不行.

我必须单击文本字段才能调出键盘.
Apple有什么更新我不知道吗?

更新:看起来我的项目或所有视图控制器都出现了问题,因为我无法在所有屏幕上显示键盘.但是当我使用上面的代码创建新项目时,它可以很好地工作.
这是问题之一:

正如您所看到的,我必须单击文本字段以显示键盘,并且从第二次开始,它可以正常工作.这个问题只发生在ios 11(模拟器和设备)上
以下是上述搜索字段的代码:

UITextFIEld *textFIEld = [[UITextFIEld alloc] initWithFrame:CGRectMake(0,215,30)];    textFIEld.backgroundcolor = [UIcolor clearcolor];    textFIEld.placeholder = @"Enter text to search";    textFIEld.borderStyle = UITextborderStyleline;    textFIEld.layer.masksToBounds=YES;    textFIEld.layer.bordercolor=[[UIcolor lightGraycolor]CGcolor];    textFIEld.layer.borderWIDth= 1.0f;    textFIEld.returnKeyType = UIReturnKeySearch;    textFIEld.delegate = self;    textFIEld.clearbuttonMode = UITextFIEldviewmodeAlways;    [UIVIEw TransitionWithVIEw:self.navigationController.navigationbar                  duration:0.55f                   options:UIVIEwAnimationoptionTransitionCrossdissolve                animations:^{                    self.navigationItem.TitleVIEw = textFIEld;                } completion:^(BOol finished) {                    [textFIEld becomeFirstResponder];                }];

我想知道有什么原因导致冲突键盘?

解决方法 我创建了一个新项目并尝试了您的代码.它在模拟器和设备iOS11上都能正常工作.显示键盘并调用通知.这是我试过的代码.

@implementation VIEwController- (voID)vIEwDIDLoad {  [super vIEwDIDLoad];  // Do any additional setup after loading the vIEw,typically from a nib.  [[NSNotificationCenter defaultCenter] addobserver:self                                           selector:@selector(keyboarDWillShow:)                                               name:UIKeyboarDWillShowNotification                                             object:nil];}- (voID)vIEwDIDAppear:(BOol)animated {  [super vIEwDIDAppear:animated];  UITextFIEld* tf = [[UITextFIEld alloc] initWithFrame:CGRectMake(10,40)];  tf.borderStyle = UITextborderStyleRoundedRect;  tf.text = @"test";  [self.vIEw addSubvIEw:tf];  if ([tf canBecomeFirstResponder]) {    [tf becomeFirstResponder];  // surely this line is called  }}- (voID)keyboarDWillShow:(NSNotification*)note {  NSDictionary* userInfo = [note userInfo];  CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;  NSLog(@"Keyboard Height: %f WIDth: %f",kbSize.wIDth);}@end

你应该检查DLog方法.我认为调用了键盘的通知,但由于DLog方法没有记录任何内容.

总结

以上是内存溢出为你收集整理的在ios 11中,becomeFirstResponder不显示键盘全部内容,希望文章能够帮你解决在ios 11中,becomeFirstResponder不显示键盘所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1063544.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存