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