允许用户通过点击来选择UIPickerView行 [英] Allowing user to select a UIPickerView row by tapping
问题描述
我正在尝试将UIPicker View的行为与iPhone代码示例中常见的行为有所不同.
I'm trying to use a UIPicker View with a behavior somehow different of what's usually seen in iPhone code examples.
我想做的是允许用户滚动选择器的内容,而不是自动选择一个选择器的行(使用选择器委托中的"didSelectRow"方法).相反,我想允许用户触摸选择器的中心行,该行会突出显示并成为选择.
What I want to do is to allow users to scroll through the picker contents, but not to select a picker's row automatically (using the "didSelectRow" method from picker's delegate). Instead, I want to allow the user to touch the center row of the picker, which gets highlighted, and becomes the selection.
有什么办法可以做到这一点?
Is there any way to achieve this?
谢谢.
推荐答案
向UIPickerView添加一个手势识别器,该手势识别器将触发对象中的目标方法:
Add a gesture recogniser to the UIPickerView which triggers a target method in your object:
myGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickerTapped:)];
[myPicker addGestureRecognizer:myGR];
// target method
-(void)pickerTapped:(id)sender
{
// your code
}
这篇关于允许用户通过点击来选择UIPickerView行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!