I’ve got UIDatePicker on UIViewController.
After user selected the date and clicked outside the UIDatePicker I would like hide UIDatePicker like:
-(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];
}
I try
[_datePicker addTarget:self action:@selector(hidePicker) forControlEvents:UIControlEventTouchUpOutside];
but event doesn’t happen, can you get me some advise?
I don’t wanna use UIControlEventValueChanged because DatePicker should not hide each time when user change the date
You cannot use
UIControlEventTouchUpOutsidefor this behavior. In your case you need to create a transparent view or button outside the picker and set action for that to dismiss the picker. Set the background color of this view/button as clear color to achieve this. On tap of the button or view, you might have to dismiss the picker.UIControlEventTouchUpOutsideis mainly used for touching inside the view and moving out the finger. While moving out of the bounds of the view, it triggers the event.