• 监听键盘- KeyBoard


    - (void)KeyBoardShowOrHide

    {

        // NSNotificationCenter 通知中心

        // 检测键盘将要消失的状态

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

        

        // 检测键盘将要弹出的状态

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

    }

    - (void)hideKeyBoard:(NSNotification *)sender

    {

        NSLog(@"键盘退出");

        // 还原

        self.view.transform = CGAffineTransformIdentity;

        

    }

    - (void)showKeyBoard:(NSNotification *)sender

    {

        //NSLog(@"%@",sender.userInfo);

        // 获取键盘高度

        CGRect rect = [[sender.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

        CGFloat keyBoardH = rect.size.height;

        

        self.view.transform = CGAffineTransformMakeTranslation(0, - keyBoardH);

        

    }

    注意:当写注册页面时,由于textField太多,用此方法会导致,第一个textField在编辑时看不见,看得见时,有没有键盘。根据李老师的提议,把textField添加到scrollView中,不过我暂时没有实现过。

  • 相关阅读:
    Linux .o a .so .la .lo的区别
    linux源码Makefile详解
    Kconfig详解
    如何将驱动程序静态编译进内核
    getpeername
    Socket programming in C on Linux | tutorial
    C Socket Programming for Linux with a Server and Client Example Code
    UDP protocol
    TCP protocol
    How to learn linux device driver
  • 原文地址:https://www.cnblogs.com/fanwenzheIOS/p/4974232.html
Copyright © 2020-2023  润新知