blocking user interaction with underlying views

烈酒焚心 提交于 2020-01-01 09:34:26

问题


In my app, i have an overlay view, which is displayed when some processing and networking is happening. It is just a semitransparent view (subclass of UIView) with a loading indicator on it, filling the whole screen.

I want to prevent any of the underlying views to recieve user-interaction (e.g. a underlying table view should not be scrolled, a button not be pressed).

What is the best way i can do this from within the overlay view?


回答1:


Just set the userInteractionEnabled property for the overlay view to YES. This will cause all touch events to occur on the overlay view and not be passed to the underlying views.




回答2:


Just set property userInteractionEnabled of your semitransparent overlay view to YES.




回答3:


I think the best way is to use these 2 methods:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

right before doing the heavy processing operations, and after completing them respectively.




回答4:


Just make sure the overlay view and all of its parent views do not have userInteractionEnabled set to NO, are not hidden, and do not have an alpha less than 0.01. Then the user's touches will interact with the overlay instead of the views visible behind it. Also be aware that it will not block interaction in an area that is not covered by its superviews: even if your view covers the whole screen, if its parent is just 10x10 then it will only block interaction within that 10x10 area covered by its parent.

You may also need to ensure that resignFirstResponder is called on any existing first responder, or the user will still be able to interact with it via the keyboard.



来源:https://stackoverflow.com/questions/7271732/blocking-user-interaction-with-underlying-views

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