确定UIPickerWheel是否正在滚动 [英] Determining if UIPickerWheel is scrolling

查看:84
本文介绍了确定UIPickerWheel是否正在滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,有没有办法确定UIPickerView目前是否滚动,我真的需要我的应用程序的功能,这非常重要。谢谢!

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!

推荐答案

每次滚动选择器时都会触发UIPickerViewDelegate方法

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

好了,我知道你需要什么。
实现一个检查选择器状态的计时器。

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];

如果timeSinceMove大于某个所需的值,即0.5秒,则将BOOL pickerMoving设置为false。否则将其设置为true。这不是检查运动的最精确方法,但我认为它应该可以完成这项工作......

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

这篇关于确定UIPickerWheel是否正在滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆