zoukankan      html  css  js  c++  java
  • 键盘的弹出与消失(获得弹出与消失的状态)

    首先需要在viewdidload内使用 如下代码,注册通知,并且使用 选择器方法,指明弹出与消失时候调用的方法

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

    然后实现keyBoardWillShow:与keyBoardWillHide:方法:

    -(void)keyBoardWillShow:(NSNotification * )notification{
        if (!isKeyBoardShow) {
            NSLog(@"键盘弹出啦");
            NSDictionary * userInfo =[notification userInfo];
            NSValue * value =[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
            CGRect keyBoardRect=[value CGRectValue];
            int height =keyBoardRect.size.height;
            self.view.frame=CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height-height);
            self.tableView.scrollEnabled=YES;
            isKeyBoardShow=YES;
        }

    }

    -(void)keyBoardWillHide:(NSNotification * )notification{
        if (isKeyBoardShow) {
            NSLog(@"键盘消失啦");
            //    _user.name=self.getName.text;
            self.tableView.scrollEnabled=NO;
            NSDictionary * userInfo =[notification userInfo];
            NSValue * value =[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
            CGRect keyBoardRect=[value CGRectValue];
            int height =keyBoardRect.size.height;
            self.view.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+height);
        }
    }

  • 相关阅读:
    猎户、双子、英仙
    第二卦,还叫我保持现状?
    昨晚的第三卦,就快万劫不复了
    明天要出去办事,看看情况
    luogu P3939 数颜色 |vector
    luogu P2701 [USACO5.3]巨大的牛棚Big Barn |动态规划
    luogu P2345 奶牛集会 |排序+树状数组
    luogu P4943 密室 |最短路
    luogu P4343 [SHOI2015]自动刷题机 |二分答案
    luogu P3110 [USACO14DEC]驮运Piggy Back |最短路
  • 原文地址:https://www.cnblogs.com/thxios/p/4894791.html
Copyright © 2011-2022 走看看