现在的位置: 首页 > 综合 > 正文

滚动的时候让键盘消失

2017年12月08日 ⁄ 综合 ⁄ 共 670字 ⁄ 字号 评论关闭
使用UIScrollViewKeyboardDismissMode实现了Message app的行为
像Messages app一样在滚动的时候可以让键盘消失是一种非常好的体验。然而,将这种行为整合到你的app很难。幸运的是,苹果给UIScrollView添加了一个很好用的属性keyboardDismissMode,这样可以方便很多。
 
现在仅仅只需要在Storyboard中改变一个简单的属性,或者增加一行代码,你的app可以和办到和Messages app一样的事情了。
 
这个属性使用了新的UIScrollViewKeyboardDismissMode enum枚举类型。这个enum枚举类型可能的值如下:
  1. UIScrollViewKeyboardDismissModeNone        // the keyboard is not dismissed automatically when scrolling 
  2. UIScrollViewKeyboardDismissModeOnDrag      // dismisses the keyboard when a drag begins 
  3. UIScrollViewKeyboardDismissModeInteractive // the keyboard follows the dragging touch off screen, and may be
  4.  pulled upward again to cancel the dismiss 
 
以下是让键盘可以在滚动的时候消失需要设置的属性:
 

抱歉!评论已关闭.