iPhone: how do I set up a clear window-size “blocker view”?

牧云@^-^@ 提交于 2019-12-13 01:40:48

问题


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:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2490574/iphone-how-do-i-set-up-a-clear-window-size-blocker-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!