It's an universal solution for keyboard avoiding that allows automatically change content inset of UIScrollView
and it's subclasses. When keyboard appears you will be able to see all content of your scroll views.
If you use CocoaPods
in your project just add it into your Podfile
pod 'EKKeyboardAvoiding'
If you don't use CocoaPods
you can compile static lib and add it to your project or just add EKKeyboardAvoidingScrollView
and EKKeyboardAvoidingScrollViewManager
files into your project
To enable keyboard avoiding set contentSize
for your scroll and use EKKeyboardAvoidingManager
class and registerScrollView:
method to register and start avoiding.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[self view] bounds]];
[scrollView setContentSize:[scrollView frame].size];
...
[[EKKeyboardAvoidingManager sharedInstance] registerScrollView:scrollView];
To disable keyboard avoiding use unregisterScrollView:
method of EKKeyboardAvoidingManager
class
[[EKKeyboardAvoidingManager sharedInstance] unregisterScrollView:scrollView];
You can also use EKKeyboardAvoidingView
class instead of UIScrollView
that automatically registers objects for keyboard avoiding. If you use xib, set the scroll view's class as EKKeyboardAvoidingView
, and put all your controls within that scroll view. You can also create it programmatically, without using xibs - just use EKKeyboardAvoidingView
as a superclass for your scroll views.
##Notes Works on iPhone/iPad iOS 5.0+