ios 设置按钮不可见,“完成"按钮在数字键盘iOS 9问题中不可见

这篇博客讨论了在iOS9中遇到的一个问题,即代码在之前的iOS版本(6,7,8)中正常工作,但在iOS9中为数字键盘添加' Done '按钮后,该按钮虽然被调用但不显示。作者通过调试发现,问题出在获取键盘窗口对象的方式上。解决方案是将获取键盘窗口的代码从`objectAtIndex:1`改为`lastObject`。修改后,当应用进入后台再回到前台时,按钮会短暂显示然后消失的问题得到了解决。
摘要由CSDN通过智能技术生成

this code is working in ios 6,7,8 but this all method is called in ios 9 but it is not visible. on number pad. here is my code.

#import "ViewController.h"

#define TAG_BUTTON_DONE 67125

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];

// Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (void)keyboardDidShow:(NSNotification *)note {

[self addButtonToKeyboard];

}

- (void)addButtonToKeyboard{

//NSLog(@"addButtonToKeyboard");

//jenish

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

// create custom button

UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];

doneButton.frame = CGRectMake(0, 163, 106, 53);

doneButton.adjustsImageWhenHighlighted = NO;

[doneButton setTag:TAG_BUTTON_DONE];

//[doneButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];

//[doneButton setImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];

[doneButton setTitle:@"Done" forState:UIControlStateNormal];

[doneButton setTintColor:[UIColor blackColor]];

[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

// locate keyboard view

int windowCount = (int)[[[UIApplication sharedApplication] windows] count];

if (windowCount < 2) {

return;

}

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];

UIView* keyboard;

for(int i=0; i

keyboard = [tempWindow.subviews objectAtIndex:i];

// keyboard found, add the button

if([[keyboard description] hasPrefix:@"

[keyboard addSubview:doneButton];

}

else if([[keyboard description] hasPrefix:@"

for(int j = 0 ; j < [keyboard.subviews count] ; j++) {

UIView* hostkeyboard = [keyboard.subviews objectAtIndex:j];

if([[hostkeyboard description] hasPrefix:@"

[hostkeyboard addSubview:doneButton ];

[hostkeyboard bringSubviewToFront:doneButton];

}

}

}

else

{

dispatch_async(dispatch_get_main_queue(), ^{

[keyboard addSubview:doneButton];

});

}

}

}

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch * touch = [touches anyObject];

if(touch.phase == UITouchPhaseBegan) {

[self.tf resignFirstResponder];

}

}

@end

then you need to go background and come on fore ground it will visible for few second than it will go hide. please help me.

thank you

解决方案

Change

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];

To :

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] lastObject];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值