iOS 之给苹果自带的纯数字键盘添加完成事件

.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");

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值