要求
:
When the keyboard is blocking the input box, the input box automatically bounces up to the top of the keyboard.
实现
:
Here's another way to use the masonry mas_updateConstraints
. This method is used to update control constraints.
The specific implementation of the demo can be downloaded to see, this is only posted when the keyboard Popup processing code:
- (void) Keyboardwillchangeframenotification: (Nsnotification *) Notification {Get keyboard Basics (animation duration vs. keyboard height)Nsdictionary *userinfo = [notification UserInfo];CGRect rect = [userinfo[Uikeyboardframebeginuserinfokey] Cgrectvalue]; cgfloat keyboardheight = cgrectgetheight (rect); cgfloat keyboardduration = [userinfo[uikeyboardanimationdurationuserinfokey] doublevalue]; //Modify the bottom margin constraint [_textfield mas_updateconstraints:^ (Masconstraintmaker *make) {make. Bottom. Mas_equalto (- Keyboardheight); }]; //Update constraint [UIView animatewithduration:keyboardduration animations:^{[self. View layoutifneeded];};}
Summarize:
- You can add Left/right/top/bottom/size/height/width/insert constraints to the control;
- library provides three methods, mas_makeconstraints add constraints, mas_updateconstraints modify constraints, Mas_ Remakeconstraints clears the previous constraint and adds a new constraint;
- a constraint on the view can be obtained by view.mas_bottom;
-
Masonry constrained animations and keyboard bounce