1

So I have my date picker set up as

func configurePicker()
{
    pickerContainer.frame = CGRectMake(0.0, 600.0, 320.0, 300.0)
    pickerContainer.backgroundColor = UIColor(red: 6/225.0, green: 232/225.0, blue: 255/225.0, alpha: 0)

    picker.frame    = CGRectMake(0.0, 20.0, 320.0, 300.0)
    let dateComponents = NSDateComponents()
    dateComponents.year = -18
    let dateComponents2 = NSDateComponents()
    dateComponents2.year = -60
    picker.maximumDate = NSCalendar.currentCalendar().dateByAddingComponents(dateComponents, toDate: NSDate(), options: nil)
    picker.minimumDate = NSCalendar.currentCalendar().dateByAddingComponents(dateComponents2, toDate: NSDate(), options: nil)
    picker.setDate(picker.maximumDate!, animated: true)
    picker.datePickerMode = UIDatePickerMode.Date
    pickerContainer.addSubview(picker)
}

as you can tell I have a minimum and maximum date set up. I also have a dismiss function I did not include. My question is how can I find out when the user is below the minimum and above maximum? What I want to do is play a gif in the background when the user is below the minimum and a separate gif when above the maximum? is there a way to tell where the user is on the date picker wheel? I understand that the date picker wheel resets past the minimum and maximum but i just want to know if there is a way to know what date the wheel is at without the user letting go. For example a conditional statement like this that works

if(picker.date > picker.maximumDate)
{
  playgif1()
}
else if(picker.date < picker.minimumDate)
{
  playgif2()
}

Above comparisons do not work gives me an error keeps saying cannot find overload for '>' or '<'

Thank You for any help

Jack
  • 275
  • 1
  • 6
  • 24
  • You can monitor if the picker value has changed yourself and manually check if the date is valid or not – Leo Dabus Nov 06 '15 at 01:50
  • Sorry Leo can't do that i need to see when it is higher than the maximum and lower and do separate gifs accordingly sorry for not making that clear – Jack Nov 06 '15 at 04:17

1 Answers1

1

As far as I know, unless Apple added a new API, UIDatePicker (and UIPickerView in general), do not have methods to get scroll events from them.

I think the best you can do is to add a target method to the picker for a ValueChanged event, which will call a method when the user has stopped scrolling on a date.

func configurePicker() {
    //...other configuration
    picker.addTarget(self, action: "datePicked:", forControlEvents: UIControlEvents.ValueChanged)
}

func datePicked(picker: UIDatePicker) {
    // compare dates
}
ryanthon
  • 2,524
  • 3
  • 17
  • 18
  • Thank you for the value changed that makes sense but I am not allowed to do that comparison that is why i left the conditional statement there hoping someone would be able to show me a comparison i can make because i get an error saying "could not find overload that accepts arguments || or > or < even though i am comparing ns dates – Jack Nov 06 '15 at 03:50
  • @ Angatvhr Sanghera you can compare dates but not like how he is suggesting – Leo Dabus Nov 06 '15 at 04:18
  • Thank you guys hopefully i figure it out very helpful community :) – Jack Nov 06 '15 at 04:25
  • Yeah, sorry for the bad code in the datePicked() function. I was kind of in a rush to leave, and typed it out a bit hastily. Glad you figured it out. – ryanthon Nov 06 '15 at 19:40