Objective c 隐藏UIDatePicker的事件

Objective c 隐藏UIDatePicker的事件,objective-c,ios,uidatepicker,uicontrolevents,Objective C,Ios,Uidatepicker,Uicontrolevents,我在UIViewController上安装了UIDatePicker 用户选择日期并在UIDatePicker外部单击后,我想隐藏UIDatePicker如下: -(void)hidePicker { [UIView beginAnimations:@"SlideOutPicker" context:nil]; [UIView setAnimationDuration:0.5]; [_datePicker setCenter: CGPointApplyAffineT

我在UIViewController上安装了UIDatePicker

用户选择日期并在UIDatePicker外部单击后,我想隐藏UIDatePicker如下:

-(void)hidePicker
{   
    [UIView beginAnimations:@"SlideOutPicker" context:nil];
    [UIView setAnimationDuration:0.5];
    [_datePicker setCenter: CGPointApplyAffineTransform(_datePicker.center, _datePicker.transform)];
    [_datePicker setTransform:CGAffineTransformMakeTranslation(0, 0)];
    [UIView commitAnimations];
}
我试着

但事情没有发生,你能给我一些建议吗


我不想使用UIControlEventValueChanged,因为DatePicker不应在每次用户更改日期时隐藏您不能使用
uicontrolEventTouchOutside
进行此行为。在您的情况下,您需要在选择器外部创建一个透明视图或按钮,并为此设置操作以关闭选择器。为此,请将此视图/按钮的背景色设置为透明色。点击按钮或视图时,您可能必须关闭选择器


UIControlEventTouchUpOutside
主要用于触摸视图内部和移出手指。当移出视图边界时,它会触发事件。

每次触摸屏幕时,只需检查触摸是否不在UIDatePicker的边界内。是否尝试设置hidden=YES?我想您可以在动画块内更改其可见性。顺便说一句,如果你正在为iOS 4+开发,那么你最好使用新的(它们实际上已经不再是新的)UIView类方法来制作动画,因为苹果不鼓励使用beginAnimations和Committeanimations块。以下是我提到的方法:

animateWithDuration:animations:
animateWithDuration:animations:completion:
animateWithDuration:delay:options:animations:completion:
更多信息请访问

animateWithDuration:animations:
animateWithDuration:animations:completion:
animateWithDuration:delay:options:animations:completion: