开发者

blocking user interaction with underlying views

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?


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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜