UIViewController-KeyboardAdditions
Swift 版本
有关 Swift 兼容版本的详细信息,请参阅 Keyboardy
描述
UIViewController+KeyboardAdditions
类别通过向 UIViewController 类扩展多个简单方法,简化了键盘处理逻辑。支持 AutoLayout 和基于 frame
的动画。
用法
-
导入类别
#import <UIViewController-KeyboardAdditions/UIViewController+KeyboardAdditions.h>
-
在
-viewWillAppear:
中注册键盘通知
[self ka_startObservingKeyboardNotifications];
- 在
-viewWillDisappear:
中注销通知
[self ka_stopObservingKeyboardNotifications];
- 使用与键盘相同的动画选项进行布局
- (void)ka_keyboardShowOrHideAnimationWithHeight:(CGFloat)height
animationDuration:(NSTimeInterval)animationDuration
animationCurve:(UIViewAnimationCurve)animationCurve {
self.containerViewBottomConstraint.constant = height;
[self.view layoutIfNeeded];
}
示例
要运行示例项目,请克隆存储库,然后从Example目录运行pod install
。
安装
UIViewController-KeyboardAdditions可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中。
pod "UIViewController-KeyboardAdditions"
作者
Andrew Podkovyrin,[email protected]
许可
UIViewController-KeyboardAdditions按照MIT许可提供。有关更多信息,请参阅LICENSE文件。