Determining if UIPickerWheel is scrolling
Hey, is there any way to dete开发者_StackOverflow中文版rmine is UIPickerView is scrolling currently, I really need that functionality for my app, it's really important. Thanks!
There is a trick to detect this but there is no delegate method/ property to detect if it's scrolling or not
- take a property as isScrolling
- set isScrolling to true in
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
or equivalent method - set isScrolling to false in
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
There is a UIPickerViewDelegate method which is basically triggered every time you scroll the picker
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
Set the delegate for your picker, implement this method and see what happens...
[EDIT] ok now I understand what you need. Implement a timer which checks the state of the picker.
checkTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(checkPicker) userInfo:nil repeats:YES];
in the above delegate method, store the last time the picker had been moved.
lastPickerDate = [[NSDate date] retain];
in the checkPicker method check how much time had elapsed from the last move
NSTimeInterval timeSinceMove = -[lastPickerDate timeIntervalSinceNow];
if timeSinceMove is bigger then some desired value i.e. 0.5 seconds, set your BOOL pickerMoving to false. else set it to true. This is not the most precise method to check for movement, but I think it should do the job...
精彩评论