Question

I'm presenting a view controller for a color picker element modally, using a UIModalFormSheet style. On the iPad, the controller doesn't take up the whole screen, and views behind are dimmed and user interaction disabled. This is great, the only problem is that I want the user to be able to "tap out" of the color picker. In other words, any tap outside of the color picker element will dismiss the color picker. I can add a gesture recognizer or invisible "tap out" button to the color picker's view, but this obviously doesn't pick up any touches outside that view. Adding gesture recognizers to the views behind doesn't work, as I assume user interaction gets automatically disabled. My code looks like so:

[_colorPicker setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:_colorPicker animated:YES completion:nil];

Any workarounds? I could present it a different way but I like how it looks and works, other than this issue. Thanks in advance!

Was it helpful?

Solution

I ended up working around the issue by changing my design a little. On the iPhone, the colorPicker presents modally, takes up the whole screen, and has a "cancel" button to dismiss. On iPad, the colorPicker instead presents in a UIPopoverController from the button that triggers it. I like this look better anyway, and it has "tap-out-to-dismiss" functionality built in, so this worked nicely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top