键盘 切换中英文输入 事件

#pragma -mark -keyBoardNotification
- (void)addNotification {
//   if(IOS_VERSION<5.0)
//     {
//         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillHideNotification object:nil];
//     }else{
//         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//     }
    if (IOS_VERSION>5.0) {
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
}

- (void)removeNotification
{
    if (IOS_VERSION>5.0) {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    }
}

- (void)keyboardWillShow:(id)notification
{

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
        NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
#else
        NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
#endif

        CGRect keyboardBounds;
        [keyboardBoundsValue getValue:&keyboardBounds];
        //键盘高度 216  汉字键盘:252
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDuration:0.3];
        //处理移动事件,将各视图设置最终要达到的状态
//        NSInteger offset = self.view.frame.size.height-keyboardBounds.origin.y;
//        NSInteger offset = keyboardBounds.origin.y;
//         CGRect listFrame = CGRectMake(0, -offset, self.view.frame.size.width,self.view.frame.size.height);
//        NSLog(@"keybodarH : %f", keyboardBounds.size.height);
        if([_textFiled isFirstResponder]) {
//            CGFloat lastY = downImageView.frame.origin.y +downImageView.frame.size.height;
//            CGFloat nowY = backgroundView.frame.size.height-keyboardBounds.size.height;
//            CGFloat offset = lastY-nowY;
//            NSLog(@"lastY:%f nowY:%f offset:%f", lastY, nowY,offset);
//            if(offset>0) {
//                backgroundView.frame = CGRectMake(0, 44-offset, 320, 460);
//            }
            if (keyboardBounds.size.height == 216) {
                backgroundView.frame = CGRectMake(0, 4, 320, 460);
            } else {
                backgroundView.frame = CGRectMake(0, 4-36, 320, 460);
            }
        }
//        239.000000 nowY:200.000000 offset:39.000000  1
        [UIView commitAnimations];
    }
}

  

以前的老代码,随便改了改

监听键盘事件。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

此通知在以下两种情况都会调用
1:键盘显示
2:当前为英文输入,点击切换为中文输入,(5.0以后,中文输入,键盘上面多出一栏来) 都会调用

英文输入时候键盘高度:216
中文输入时候键盘高度:252

这代码,真它丫乱。 (T_T)

转载于:https://www.cnblogs.com/penn-wang/archive/2013/01/10/2854878.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值