iOS 之给苹果自带的纯数字键盘添加完成事件
2013-09-10 17:46
295 查看
.h文件中添加一个按钮的属性
{
UIButton *doneInKeyboardButton;
}
在.m文件中添加以下代码就可实现纯数字代码添加完成事件
- (void)viewDidLoad
{
[super
viewDidLoad];
//注册通知
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(handleKeyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(handleKeyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
#pragma mark 键盘
- (void)handleKeyboardWillHide:(NSNotification *)notification
{
if (doneInKeyboardButton.superview)
{
[doneInKeyboardButton
removeFromSuperview];
}
}
- (void)handleKeyboardDidShow:(NSNotification *)notification
{
if (doneInKeyboardButton ==
nil)
{
doneInKeyboardButton = [UIButton
buttonWithType:UIButtonTypeCustom];
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)finishAction
{
NSLog(@"aa");
}
{
UIButton *doneInKeyboardButton;
}
在.m文件中添加以下代码就可实现纯数字代码添加完成事件
- (void)viewDidLoad
{
[super
viewDidLoad];
//注册通知
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(handleKeyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(handleKeyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
#pragma mark 键盘
- (void)handleKeyboardWillHide:(NSNotification *)notification
{
if (doneInKeyboardButton.superview)
{
[doneInKeyboardButton
removeFromSuperview];
}
}
- (void)handleKeyboardDidShow:(NSNotification *)notification
{
if (doneInKeyboardButton ==
nil)
{
doneInKeyboardButton = [UIButton
buttonWithType:UIButtonTypeCustom];
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)finishAction
{
NSLog(@"aa");
}
相关文章推荐
- ios隐藏数字键盘 --在数字键盘左下角添加“完成”按钮的实现原理
- IOS数字键盘左下角添加完成按钮的实现方法
- ios在数字键盘左下角添加“完成”按钮的实现原理
- iOS 数字输入键盘添加一个完成按钮
- ios在数字键盘左下角添加“完成”按钮的实现原理
- iOS 数字键盘完成键
- 解决 jquery在iOS系统自带键盘无法触发keyup,keydown,keypress事件
- (判断第三方输入法)在系统数字键盘上添加“完成”按钮引发的问题思考
- iOS8数字键盘左下角添加完成按钮的核心代码如下:
- 解决 jquery在iOS系统自带键盘无法触发keyup,keydown,keypress事件
- UIKeyboardTypeNumberPad 数字键盘添加完成按钮
- 数字键盘添加“完成”按钮
- ios 自带输入法无法触发 keyup等键盘事件的修复
- iOS8数字键盘左下角添加完成按钮
- 给数字键盘添加完成按钮的坑
- ios 自带输入法无法触发 keyup等键盘事件的修复
- iOS开发- runtime基本用法解析和用runtime给键盘添加工具栏和按钮响应事件
- iOS 键盘添加完成按钮,delegate和block回调
- ios8数字键盘添加完成
- ios 键盘右上角添加完成按钮