UIView added as an UIWindow subview doesn't respond to taps

后端 未结 3 686
梦如初夏
梦如初夏 2021-01-18 23:03

I\'ve added a UIView containing a UITapGestureRecognizer as my key window\'s subview. It shows properly, however when I tap my view, the target met

3条回答
  •  天涯浪人
    2021-01-18 23:47

    I ended up being able to create a full-screen subview which accepted gestures by adding it to the app's keyWindow, assuming makeKeyAndVisible has been called first:

    myView.hidden = YES;
    [[[UIApplication sharedApplication] keyWindow] addSubview:myView];
    

    Then to show it above the status bar:

    [[UIApplication sharedApplication] keyWindow].windowLevel = UIWindowLevelStatusBar + 1;
    myView.hidden = NO;
    

    And to change it back:

    [[UIApplication sharedApplication] keyWindow].windowLevel = UIWindowLevelNormal;
    myView.hidden = YES;
    

    This just changes the position of your app's main window (including all of its subviews) within the window hierarchy. Hope that helps!

提交回复
热议问题