antongaenko/UIViewController-KeyboardAnimation
소개
UIViewController 카테고리에서 키보드 표시 및 숨김 애니메이션을 처리합니다.
디자인 및 미디어측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalUIViewController-KeyboardAnimation
Easy way to handle iOS keyboard showing/dismissing.
Introduction
Working with iOS keyboard demands a lot of duplicated code. This category allows you to declare your animations with smooth keyboard animation timing and write very little code.
Demo

Try it yourself
pod try UIViewController+KeyboardAnimation
Example
Imagine that you need to implement chat-like input over keyboard. OK, import this category.
#import <UIViewController+KeyboardAnimation.h>
Then make autolayout constraint between your input bottom and superview botton in Interface Builder, connect it with your view controller implementation through IBOutlet.
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *chatInputBottomSpace;
Then subscribe to keyboard in place you like (viewWillAppear is the best place really).
@weakify(self)
[self an_subscribeKeyboardWithAnimations:^(CGRect keyboardRect, NSTimeInterval duration, BOOL isShowing) {
@strongify(self)
self.chatInputBottomSpace.constant = isShowing ? CGRectGetHeight(keyboardRect) : 0;
[self.view layoutIfNeeded];
} completion:nil];
That’s all!
Don’t forget to unsubscribe from keyboard events (viewWillDisappear is a my recommendation). Calling category method will do all “dirty” work for you.
[self an_unsubscribeKeyboard];
For more complex behaviour (like in demo section) you can use extended API call with before animation section.
@weakify(self)
[self an_subscribeKeyboardWithBeforeAnimations:^(CGRect keyboardRect, NSTimeInterval duration, BOOL isShowing) {
@strongify(self)
self.isKeaboardAnimation = YES;
[UIView transitionWithView:self.imageView duration:duration options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
if (isShowing) {
self.imageView.image = [self.imageView.image applyLightEffect];
} else {
[self.imageView hnk_setImageFromURL:self.model.cardImageUrl];
}
} completion:nil];
} animations:^(CGRect keyboardRect, NSTimeInterval duration, BOOL isShowing) {
@strongify(self)
self.headerHeight.constant = isShowing ? kHeaderMinHeight :kHeaderMaxHeight;
self.panelSpace.constant = isShowing ? CGRectGetHeight(keyboardRect) : 0;
for (UIView* v in self.headerAlphaViews) {
v.alpha = isShowing ? 0.0f : 1.0f;
}
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
@strongify(self)
self.isKeaboardAnimation = NO;
}];
Sinse version 1.3 you could add reaction for UIKeyboardWillChangeFrameNotification with an_subscribeKeyboardFrameChangesWithAnimations/an_unsubscribeKeyboardFrameChanges (thanks @timaktimak for PR 🙌)
Underhood
This category registers/unregisters your view controller to UIKeyboardWillShowNotification/UIKeyboardWillHideNotification. Also it holds animation blocks, so you really need to provide weak reference to self (i use @weakify/@strongify from ReactiveCocoa dependency).
Installation
Add the following to your CocoaPods Podfile
pod 'UIViewController+KeyboardAnimation', '~> 1.3'
or clone as a git submodule,
or just copy files
License
All this code is available under the MIT license.
Contact
Follow me on Twitter or Github
More sources
Simple category to show loading status in a navigation bar (left/right items or title) UINavigationItem-Loading
관련 프로젝트 살펴보기
불러오는 중…