3

如何利用当前旋转的瞬时值UIPickerView?(UISlider有一个“连续”模式,但UIPickerView没有。)

任何解决方法的想法?还是我错过了什么?

4

3 回答 3

0

UIPickerView 的委托只让你得到选择的一个:

– pickerView:didSelectRow:inComponent:

You won't get an event when the picker is spinning, for example like the one you could get in a UIScrollView when is scrolling.

恐怕没有直接的方法得到它

于 2013-10-14T10:29:51.717 回答
0

这可以通过 CADisplayLink 来实现

@property (nonatomic, strong) CADisplayLink *displayLink;

self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLink:)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:UITrackingRunLoopMode];

- (void) handleDisplayLink:(CADisplayLink *) displayLink
{
    NSLog(@"%s %ld", __func__, [self selectedRowInComponent:0]);
}
于 2017-11-10T15:01:28.393 回答
0

要从 a 中获取连续数据UIPickerView,您只需要启动一个计时器并调用选择器的selectedRow(inComponent:)函数。

像这样的……</p>

class TextSettingsViewController: UIViewController {

    @IBOutlet fileprivate weak var picker: UIPickerView!

    weak var timer: Timer?

    deinit {
        timer?.invalidate()
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let timer = Timer(timeInterval: 0.1, repeats: true) { [unowned self] timer in
            let row = self.picker.selectedRow(inComponent: 0)
            print("selectedRow: \(row)")
        }

        // You need to add the timer to UITrackingRunLoopMode so it fires while scrolling the picker
        let runLoop = RunLoop.current
        runLoop.add(timer, forMode: .commonModes)
        runLoop.add(timer, forMode: .UITrackingRunLoopMode)

        self.timer = timer
    }
}
于 2017-07-01T11:48:19.723 回答