TXViewKeyboardResizer 1.0.3

TXViewKeyboardResizer 1.0.3

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2015

Maintained by Toshiro Sugii.



  • By
  • rtoshiro

It automatically resizes you UIView when keyboard appears.

It can be used with any kind of UIViews.

If your view extends a UIScrollView, you need to adjust your UIScrollView.contentSize after resizing.

It was inspired by android:windowSoftInputMode="adjustResize" from Android.

Usage

First, choose the UIView that is going to be resized when keyboards appears.

Controller

Then, you need to check your Autolayout configuration or Autoresize values.

Here, i am going to use Autoresize as it is a little bit easier in that case.

Autoresize

With autoresize configured, when UIView resizes, our UITextField is positioned automaticaly.

Now we can call startKeyboardResizerObserver(WithDelegate:) inside our UIViewController:

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];

  [self.scrollView startKeyboardResizerObserverWithDelegate:self];
}

We must remember stop observing when we are done with keyboard:

- (void)viewWillDisappear:(BOOL)animated
{
  [super viewWillDisappear:animated];

  [self.scrollView stopKeyboardResizerObserver];
}

Delegate

And then, you can adjust your view per need:

- (void)viewWillResize:(UIView *)view;
- (void)viewDidResize:(UIView *)view;
- (void)viewDidTap:(UIView *)view;

We can close the keyboard, for example:

- (void)viewDidTap:(UIView *)view
{
  for (UIView *subview in self.scrollView.subviews)
  {
    if ([subview isMemberOfClass:[UITextField class]])
      [((UITextField *)subview) resignFirstResponder];
  }
}

Resize

Requirements

iOS 6.+

Installation

TXViewKeyboardResizer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TXViewKeyboardResizer"

License

TXViewKeyboardResizer is available under the MIT license. See the LICENSE file for more info.