UIPickerView, detect “rolling wheel” start and stop?

前端 未结 7 1599
悲哀的现实
悲哀的现实 2020-12-18 04:30

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
相关标签:
7条回答
  • 2020-12-18 05:16

    Expanded @iluvatar_GR answer

    extension UIView { 
    func isScrolling () -> Bool {
    
        if let scrollView = self as? UIScrollView {
            if (scrollView.isDragging || scrollView.isDecelerating) {
                return true
            }
        }
    
        for subview in self.subviews {
            if ( subview.isScrolling() ) {
                return true
            }
        }
        return false
    }
    func waitTillDoneScrolling (completion: @escaping () -> Void) {
        var isMoving = true
        DispatchQueue.global(qos: .background).async {
        while isMoving == true {
            isMoving = self.isScrolling()
        }
            DispatchQueue.main.async {
                completion()}
    
        }
    }
    }
    
    0 讨论(0)
提交回复
热议问题