0

1.I don't like to use any third party framework to do it,only constraint is there any possibility ?

Ok what i was tried :)

enter image description here

use the constraints IBOutlet i need to update it..

-(void)keyboardDidShow:(NSNotification*)aNotification{
    NSDictionary* info = [aNotification userInfo];

    double animationduration =[info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect keyboardEndFrame =[info[UIKeyboardFrameEndUserInfoKey] CGRectValue];

    NSLog(@"this is user info notification keyboard did show==%@",info);
}

guide me friends to achieve this :)

Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47

3 Answers3

2

Follow these steps:

  • Whenever keyboard appears just change the constant of outlet of constraint as per your need.
  • Then update the constraint by calling [self updateConstraintIfNeeded]
  • Then update layout of view by calling [self layoutIfNeeded]
  • Whenever keyboard comes down change your constant back to the original one
  • follow 3 & 4 again

TIP:
calling layout update call in UIView animation block will help you with smooth transition.

If you want to get keyboard size:

- (void)keyboardWillShow:(NSNotification*)notification {
   NSDictionary *info = [notification userInfo];
   CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
   CGFloat deltaHeight = kbSize.height - _currentKeyboardHeight; 
   // Write code to adjust views accordingly using deltaHeight
   _currentKeyboardHeight = kbSize.height;

}

Thats all.

iAnurag
  • 9,286
  • 3
  • 31
  • 48
1

You have to change the constant property in your NSLayoutConstraint. Then you have to refresh the layout.

If your IBOutlet is:

@property (nonatomic, weak) IBOutlet NSLayoutConstraint *bottomConstraint;

and the initial constant value in that NSLayoutConstraint is bottomInitialValue

Initial value and IBOutlet

The code should be:

- (void) keyboardDidShow:(NSNotification*) aNotification
{
    NSDictionary* info = [aNotification userInfo];

    double animationduration =[info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect keyboardEndFrame =[info[UIKeyboardFrameEndUserInfoKey] CGRectValue];

    bottomConstraint.constant = keyboardEndFrame.size.height + bottomInitialValue;
    [self.view layoutIfNeeded];
}

When the keyboard dissapear, you have to set the constant property to initial value:

bottomConstraint.constant = bottomInitialValue;
[self.view layoutIfNeeded];
torcelly
  • 516
  • 4
  • 8
0

Get imageView Top constraints IBOutlet

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintImageViewTop;

Up

- (void)keyboardWillShow:(NSNotification*)notification
 {
    NSDictionary *info = [notification userInfo];
    CGSize kbHeight = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    constraintImageViewTop.constant = constraintImageViewTop.constant - kbSize.height;
 }

Down

- (void)keyboardWillHide:(NSNotification *)notification
 {
    NSDictionary *info = [notification userInfo];
    CGSize kbHeight = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    constraintImageViewTop.constant = constraintImageViewTop.constant + kbSize.height;
 }

Make PhoneNumber(textfield) bottom constraints priority low enter image description here

Shrikant Tanwade
  • 1,391
  • 12
  • 21