UIPickerView, detect “rolling wheel” start and sto

2019-02-13 22:46发布

I just discovered that if I do the following:

  1. Click the button that animates a UIPickerView into my view
  2. Quickly start the wheel rolling towards, then past, the last item
  3. Dismiss the view with a button

Then it has not yet selected the last item yet.

I tried this by simply outputting to the console whenever the didSelectRow method was fired, and it fires when the wheel stabilizes on the last item.

Can I detect that the wheel is still rolling, so that I can delay checking it for a selected value until it stabilizes?

If it matters, I'm programming in MonoTouch, but I can read Objective-C code well enough to reimplement it, if you have a code example that is.

7条回答
Anthone
2楼-- · 2019-02-13 23:27

Expanded @iluvatar_GR, @Robert_at_Nextgensystems answer

Used Gesture, UIScrollView isDragging or isDecelerating.

// Call it every time when Guesture action.
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
    // Changes the button name to scrolling at the start of scrolling.
    DispatchQueue.main.async {
       self._button.setTitle("Scrolling...", for: .normal)
       self._button.isEnabled = false
       self._button.backgroundColor = Utils.hexStringToUIColor(hex: "FF8FAE")
    }

    // Indication according to scrolling status
    _datePicker.waitTillDoneScrolling(completion: {
        print("completion")
        DispatchQueue.main.async {
           self._button.setTitle("Completion", for: .normal)
           self._button.isEnabled = true
           self._button.backgroundColor = Utils.hexStringToUIColor(hex: "7CB0FF")
        }
    })
}

[SWIFT4] Share Example Source link!

enter Sample Source link

查看更多
登录 后发表回答