views:

171

answers:

2

I feel like this should be obvious to me, but for some reason I can't figure this out. I have a navigation interface with nav bar, tool bar, and primary view. Sometimes the user takes an action that causes a progress indicator to appear in the middle of the view.

While the progress indicator (which is a custom UIView) in spinning in the middle, I want no touch input to be allowed to go to any of the underlying interface (main view, nav bar, toolbar, etc). But this doesn't seem trivial.

I've tried (and failed) to create a simple view whose only job is to swallow touch input and use it as a window subview-- no dice, it never gets the touch events (and yes, it does have userInteractionEnabled). I've tried to bolt it on as a transparent modal view controller, but those don't seem to ever be transparent.

Thoughts? What am I missing?

Thanks!

+1  A: 

You can create a transparent UIWindow with a windowLevel > 1.

KennyTM
Thanks-- I thought about this, but Speaketh the Apple docs: "Although iPhone OS supports layering windows on top of each other, your application should never create more than one window." Having been rejected from Apple's approval process for less than this before, I hope to find a way that is not characterized so negatively in the docs?
quixoto
Kenny: I am a fool for not being able to do something similar with a vanilla UIView in the normal app window that's transparent and sits above everything else in my app? I have tried what I thought was this, but touches always seem to pass through.
quixoto
+1  A: 

You could stop the applicaiton from accepting interaction events with

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

And then start taking events again

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

But I would be extremely careful with that as it stops the user from interacting with your app all together.

To suggest another route. You could display a UIAlertView created with just the init method to house the the progress indicator in the middle of it. If you use the init method than there will be no buttons for the user to interact with. Then when ever you are done you can dismiss the alert view. If you wanted to give the user a way to cancel the action you can even use a button on the alert view to cancel it.

Brandon Bodnár
Brandon, thanks for the reply. I was not aware of the ability to globally ignore events-- in this case, that might be most expedient for me, although I believe it's a pretty big hammer for what I'm doing. The custom alert view is interesting, too, but definitely seems a little kludgey-- I feel like this should be simpler! :) Thanks
quixoto