<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          KeyboardObserver鍵盤事件處理

          聯(lián)合創(chuàng)作 · 2023-09-27 12:31

          KeyboardObserver 是為了處理不太復(fù)雜的鍵盤事件。

          特性:

          • 處理不太復(fù)雜的鍵盤事件。

          • 不是使用 NSNotification,而是使用 event。

          區(qū)別:

          不用 KeyboardObserver.swift

          let keyboardNotifications = [
              UIKeyboardWillShowNotification,
              UIKeyboardWillHideNotification,
              UIKeyboardWillChangeFrameNotification
          ]
          override func viewDidLoad() {    super.viewDidLoad()
          }
          override func viewWillAppear(animated: Bool) {    super.viewWillAppear(animated)
          
              keyboardNotifications.forEach {
                  NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardEventNotified:", name: $0, object: nil)
              }
          }
          override func viewWillDisappear(animated: Bool) {    super.viewWillDisappear(animated)
          
              keyboardNotifications.forEach {
                  NSNotificationCenter.defaultCenter().removeObserver(self, name: $0, object: nil)
              }
          }func keyboardEventNotified(notification: NSNotification) {    guard let userInfo = notification.userInfo else { return }    let keyboardFrameEnd = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()    let curve = UIViewAnimationOptions(rawValue: UInt(userInfo[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber))    let duration = NSTimeInterval(userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber)    let distance = UIScreen.mainScreen().bounds.height - keyboardFrameEnd.origin.y    let bottom = distance >= bottomLayoutGuide.length ? distance : bottomLayoutGuide.length
          
              UIView.animateWithDuration(duration, delay: 0.0, options: [curve], animations:
                  { [weak self] () -> Void in
                      self?.textView.contentInset.bottom = bottom            self?.textView.scrollIndicatorInsets.bottom = bottom
                  } , completion: nil)
          }

          用 KeyboardObserver.swift

          let keyboard = KeyboardObserver()override func viewDidLoad() {    super.viewDidLoad()
          
              keyboard.observe { [weak self] (event) -> Void in
                  guard let s = self else { return }        switch event.type {        case .WillShow, .WillHide, .WillChangeFrame:            let distance = UIScreen.mainScreen().bounds.height - event.keyboardFrameEnd.origin.y            let bottom = distance >= s.bottomLayoutGuide.length ? distance : s.bottomLayoutGuide.length
          
                      UIView.animateWithDuration(event.duration, delay: 0.0, options: [event.curve], animations:
                          { [weak self] () -> Void in
                              self?.textView.contentInset.bottom = bottom                    self?.textView.scrollIndicatorInsets.bottom = bottom
                          } , completion: nil)        default:            break
                  }
              }
          }
          瀏覽 23
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  西西午夜无码视频色欲 | 亚洲色导航五月 | 亚洲AV无码秘 蜜桃永瀬ゆい | 靠逼免费视频网站 | 超碰在线免费成人午夜剧场97 |