iOS development-use AutoLayout pop-up keyboard

Source: Internet
Author: User

Reference:

http://segmentfault.com/q/1010000002420050

http://blog.csdn.net/qq448631961/article/details/40345653

Ideas:

A view with a height of 0 (using a low priority constraint) is tucked into the entire view, changing the height of the view when the keyboard changes.

Constraint has a unique property that can be modified constant, I admit that its name is really confusing ...
As an example of the height problem mentioned by the main question, you can save this highly constraint reference when the keyboard appears and is closed

-(void) keyboarddidshownotification
{
Self.viewHeightConstraint.constant = 100.F;
[Self.myview Layoutifneed];
}

-(void) keyboarddidhidenotification
{
Self.viewHeightConstraint.constant = 300.F;
[Self.myview Layoutifneed];
}

My Code:

Registration NOTICE:

   1:  object: nil];

Constraints

@property (Nonatomic,strong) nslayoutconstraint* keyboardconstraint;

Start at 0

   1:  self.keyboardconstraint = [Nslayoutconstraint constraintWithItem:self.keyboardView attribute: Nslayoutattributeheight relatedby:nslayoutrelationequal Toitem:nil Attribute:nslayoutattributenotanattribute Multiplier:1 constant:0];

   1:  -(void) Keyboardwillshow: (nsnotification *) notification{
   2:      cgrect kbframe = [[[Notification UserInfo] Objectforkey:uikeyboardframeenduserinfokey] Cgrectvalue];
   3:      self.keyboardConstraint.constant = kbFrame.size.height;
   4:      [Self.view addConstraint:self.keyboardConstraint];
   5:      //    [Self.inputview needsupdateconstraints];
   6:      [Self.view setneedslayout];
   7:      [Self.view layoutifneeded];
   8:      if (Self.messages.count > 0) {
   9:      Nsindexpath *idxp = [Nsindexpath indexpathforrow: (self.messages.count-1) insection:0];
  Ten:          [Self.tableview scrolltorowatindexpath:idxp atscrollposition: Uitableviewscrollpositionbottom Animated:yes];}
  11:      
  :  }
  :  
  :  -(void) keyboardwillhidden{
  15:      
  :      [Self.view Endediting:yes];
  :      [UIView animatewithduration:0.25 animations:^{
  :          //        self.keyboardConstraint.constant = 0;
  :          self.keyboardConstraint.constant = 0;
  :          //        [Self.view removeConstraint:self.keyboardConstraint];
  £ º          [Self.view setneedslayout];
  :          [Self.view layoutifneeded];
  :      }];
  24:      
  :  }

iOS development-use AutoLayout pop-up keyboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.