Determining if UIPickerWheel is scrolling

走远了吗. 提交于 2019-12-02 08:53:43

问题


Hey, is there any way to determine is UIPickerView is scrolling currently, I really need that functionality for my app, it's really important. Thanks!


回答1:


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...




回答2:


There is a trick to detect this but there is no delegate method/ property to detect if it's scrolling or not

  1. take a property as isScrolling
  2. set isScrolling to true in func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? or equivalent method
  3. set isScrolling to false in func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)


来源:https://stackoverflow.com/questions/5304839/determining-if-uipickerwheel-is-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!