键盘设置

来源:互联网 发布:java 登录验证码 编辑:程序博客网 时间:2024/04/28 15:46

   

键盘的调用  打开1


[theTextField becomeFirstResponder];

关闭


[theTextField resignFirstResponder];








 在viewdidLoad中添加

    // 键盘的frame发生改变时发出的通知(位置和尺寸)

    //    UIKeyboardWillChangeFrameNotification

    //    UIKeyboardDidChangeFrameNotification

    // 键盘显示时发出的通知

    //    UIKeyboardWillShowNotification

    //    UIKeyboardDidShowNotification

    // 键盘隐藏时发出的通知

    //    UIKeyboardWillHideNotification

    //    UIKeyboardDidHideNotification

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardDidShow:)name:UIKeyboardWillChangeFrameNotificationobject:nil];    

    



//keyBoard已经展示出来

- (void)keyboardDidShow:(NSNotification *)notification

{

//    NSValue* aValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];

//    CGRect keyboardRect = [aValue CGRectValue];

//    CGRect keyboardFrame = [self.view convertRect:keyboardRect fromView:[[UIApplication sharedApplication] keyWindow]];

//    CGFloat keyboardHeight = keyboardFrame.size.height;

//    NSLog(@"##keboardHeight=%.2f",keyboardHeight);

    //lastView最底层的View

    self.lastView.frame = CGRectMake(0, -100,DEF_SCREEN_WIDTH,DEF_SCREEN_HEIGHT);

//    self.ButtonView.center = CGPointMake(DEF_SCREEN_WIDTH/2, DEF_SCREEN_HEIGHT/2 - 40);

}


0 0