是否检测到用户何时在UIDatePicker中点击选择指示器? [英] Detect when user taps the selection indicator in a UIDatePicker?

查看:36
本文介绍了是否检测到用户何时在UIDatePicker中点击选择指示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测用户何时在UIDatePicker中点击选择指示器?

How can I detect when the user taps the selection indicator in a UIDatePicker?

没有此功能,用户必须滚动到其他日期,然后再次返回以选择日期选择器向上滑动时显示在选择指示器下方的日期.

Without this the user has to scroll to some other date and then back again to pick the date which is displayed under the selection indicator when the date picker slides up.

非常感谢,
呆呆

Thanks a lot,
Stine

更新:这是我自己能想到的唯一解决方案:

UPDATE: This is the only solution I could come up with myself:

UIDatePicker *aDatePicker = [[UIDatePicker alloc] init];
self.datePicker = aDatePicker;
[aDatePicker release];
[self.datePicker addTarget:self action:@selector(datePicked:) forControlEvents:UIControlEventValueChanged];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(datePicked:)];    
[self.datePicker addGestureRecognizer:tap];
[tap release];

这意味着当用户实际旋转滚轮时, datePicked 将被调用两次.

Which means that datePicked will be called twice when the user actually rotates the wheel.

更新:上面提到的解决方案不适用于UIPickerViews.在这些情况下,我不知道如何实现所需的行为.

UPDATE: The above mentioned solution does not work for UIPickerViews though. I do not know how to achieve the wanted behavior in those cases.

推荐答案

您可以通过以下方式进行一些调整:-

You can do some tweak in this way:-

在.h文件中符合委托< UIGestureRecognizerDelegate>

UITapGestureRecognizer* gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickerViewTapGestureRecognized:)];
[yourDatePicker addGestureRecognizer:gestureRecognizer];
gestureRecognizer.delegate=self;
gestureRecognizer.numberOfTapsRequired=2;//Whenever you do double tap it will called. So allow user to do double tap on selected date.

//下面是Delegate方法

//Below is the Delegate method

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

//下面的方法将在双击时触发

//Below method will trigger when do the double tap

-(void)pickerViewTapGestureRecognized:(UITapGestureRecognizer*)recognizer
{
   UIDatePicker *datePicker=(UIDatePicker*)[[recognizer view] viewWithTag:101];
   NSLog(@"datePicker=%@", datePicker.date);
 }

这篇关于是否检测到用户何时在UIDatePicker中点击选择指示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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