一、数字键盘上添加移除按钮
- (void)handleKeyboardDidShow:(NSNotification *)notification
{
if (doneInKeyboardButton == nil)
{
doneInKeyboardButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
if(screenHeight==568.0f){//爱疯5
doneInKeyboardButton.frame = CGRectMake(0, 568 - 53, 106, 53);
}else{//3.5寸
doneInKeyboardButton.frame = CGRectMake(0, 480 - 53, 106, 53);
}
doneInKeyboardButton.adjustsImageWhenHighlighted = NO;
//图片直接抠腾讯财付通里面的= =!
[doneInKeyboardButton setImage:[UIImage imageNamed:@"btn_done_up@2x.png"] forState:UIControlStateNormal];
[doneInKeyboardButton setImage:[UIImage imageNamed:@"btn_done_down@2x.png"] forState:UIControlStateHighlighted];
[doneInKeyboardButton addTarget:self action:@selector(finishAction) forControlEvents:UIControlEventTouchUpInside];
}
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
if (doneInKeyboardButton.superview == nil)
{
[tempWindow addSubview:doneInKeyboardButton]; // 注意这里直接加到window上
}
}
- (void)handleKeyboardWillHide:(NSNotification *)notification
{
if (doneInKeyboardButton.superview)
{
[doneInKeyboardButton removeFromSuperview];
}
}
关闭键盘:
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘
以上部分摘自code4app.com