The overlay UIAppDelegate overlay window makes the user unable to touch UIActivityViewController extensions when it is displayed

I am creating an overlay that will cover all the displayed views on the screen. This overlay always appears even if the rootViewController changes by clicking or presenting.

My idea

  • Create a CustomWindow , which is a subclass of UIWindow . After that, replacing the default window with UIApplication with CustomWindow , create a new rootViewController for my new window.
  • In CustomWindow , I have overlay (is UIView ). overlay have a light gray color with alpha, and each event on overlay will go to the bottom.
  • When CustomWindow adds a new subview, I will bring overlay to the beginning. Make sure that overlay will be on top in each case.

Customwindow

 @implementation CustomWindow - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _overlay = [[UIView alloc] initWithFrame:self.bounds]; _overlay.userInteractionEnabled = NO; _overlay.backgroundColor = [UIColor lightGrayColor]; _overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self addSubview:_overlay]; } return self; } - (void)didAddSubview:(UIView *)subview { [super didAddSubview:subview]; [self bringSubviewToFront:_overlay]; } @end 

Everything works perfectly in every case, even when clicking, presenting or changing rootViewController .

Problem

But when I show the UIActivityViewController , I cannot click on any extensions that display on the UIActivityViewController .

Magically

  • When I go beyond the UIActivityViewController or click the Cancel Button , the UIActivityViewController usually rejected.

  • If I change the overlay color to clearColor , it works fine.

My question

  • How can I touch extensions when I have overlay on the window and overlay has color?

  • If I can’t, can someone tell me why this is happening? This is ideal when you can quote the reason from the document.

I am sure this is not related to the way I initialize the UIActivityViewController or the way I show the UIActivityViewController .

For a more detailed and easy creation, here I created a debug repo . You can check it for debugging if you want.

MORE

I found a problem pretty similar to this problem on Android . But I'm not sure, because I have not seen an official document about this from Apple. One more thing - changing the color to clearColor can affect the touch. So, in fact, I don’t think they are the same.

+5
source share
1 answer

This is due to the UIRemoveView (private) in the hierarchy. As far as I can tell, your application cannot send events directly to remote views. I suspect that this is a security measure that prevents you from presenting a sharing dialog and automatically sending a touch event to it to perform an external action that the user did not request. Remote views do not start in your application. The Copy button interacts with an XPC link.

All of this means that if the remote view is covered in one of your views, there is no way (at least I found) to interact with it. You must make sure that you do not close it.

It is actually simple. The thing that stores the remote view is called UITransitionView and is used for other things at the OS level that you probably shouldn't cover as well. So do not do this:

 - (void)didAddSubview:(UIView *)subview { [super didAddSubview:subview]; if ([subview isKindOfClass:NSClassFromString(@"UITransitionView")]) { // To raise it above your overlay; // otherwise it immediately above the view controller (below the overlay) [self bringSubviewToFront:subview]; } else { [self bringSubviewToFront:self.overlay]; } } 

But ... It requires you to talk about UITransitionView in your code. This is both a fragile and possibly forbidden use of private APIs.

Otherwise, you will have to wrap your UIActivityViewController requests with some calls / notifications that indicate that the window will not span the views until we finish (which you will need to clear in the completion handler).

+3
source

Source: https://habr.com/ru/post/1273114/


All Articles