# SXKeyboardViewControl **Repository Path**: poos/SXKeyboardViewControl ## Basic Information - **Project Name**: SXKeyboardViewControl - **Description**: 自动控制viewController的textView和textField被键盘遮挡问题,引入.h即可 - **Primary Language**: Objective-C - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 9 - **Forks**: 1 - **Created**: 2017-04-12 - **Last Updated**: 2025-08-01 ## Categories & Tags **Categories**: ios-modules **Tags**: None ## README # SXKeyboardViewControl 自动控制有键盘时候界面的升起和落下 >自动控制viewController的textView和textField被键盘遮挡问题 ~~引入.h即可~~ >适应各种界面view,scrollView,tabView等 >~~只需一步,引入头文件即可 import "UIViewController+SXKeyboardViewControl.h"~~ --- #### 示例效果图 ![img](Untitled3.gif) ![img](Untitled2.gif) ![img](Untitled.gif) ## //最近更新 ### 推荐的使用方式: #### 在父类里面创建,并设置一个开关 ``` SuperClass.h //有键盘-设置Yes会调整view @property (nonatomic,assign) BOOL isKeyboard;//默认No SuperClass.m - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (_isKeyboard) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardNotification:) name:UIKeyboardWillChangeFrameNotification object:nil]; } } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; if (_isKeyboard) { [self.view endEditing:YES]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } } ``` ### 之前方案弊端: 1. 在分类重写系统方法, 可能会带来其他不必要的麻烦 2. 所有的VC都进行监听, 增加了系统开销