Search code examples
iosios6uikit

Show UIPickerView like a keyboard, without UITextField


I'm looking for a way to present a UIPickerView when the user taps on a UIBarButtonItem. Imagine a filter for the table view results.

I know I could use a UITextField inputView, but this would not be the case -- all I have is a UIBarButtonItem and a UITableView.

I've seen into using a UIActionSheet, but it does not look natural, specially when it's animating to show.

Would animating the UIView on and off the screen manually the only option?

The app is iOS 6+ and iPhone only, so I don't need to keep compatibility with any other versions/idioms.


Solution

  • It might not be your only option but animating the UIPickerView should be relatively easy for you to do. Add the picker view so it's displayed off the bottom of the screen. When it's time to animate it in:

    [UIView animateWithDuration:0.3 animations:^{
        self.datePicker.frame = CGRectMake(0, self.view.bounds.size.height - datePicker.bounds.size.height, datePicker.bounds.size.width, datePicker.bounds.size.height);
    }];
    

    And when it's time to hide it:

    [UIView animateWithDuration:0.3 animations:^{
        self.datePicker.frame = CGRectMake(0, self.view.bounds.size.height, datePicker.bounds.size.width, datePicker.bounds.size.height);
    }];