使整个iOS应用程序屏幕变暗的最佳方法

时间:2018-10-19 07:30:16

标签: ios touch overlay uiwindow

在我的应用中,我需要使整个应用的整个屏幕变暗。我正在使用重叠窗口UIWindow *alphaWindow属性来做到这一点,

self.alphaWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.alphaWindow.backgroundColor = [UIColor blackColor];
self.alphaWindow.windowLevel = UIWindowLevelAlert+1;
self.alphaWindow.hidden = NO;
self.alphaWindow.userInteractionEnabled = NO;
self.alphaWindow.rootViewController = [UIViewController new];
self.alphaWindow.alpha = 0.5;

除了在两种特殊情况下之外,这还算不错:

  1. QLPreviewController中的内部(导航栏下方的所有内容)在显示图片以外的任何内容时都不会受到触摸(奇怪的是,图片运行良好)。
  2. UIImagePickerController也是如此;在导航栏下方没有收到触摸。

我的问题是:

  • 这两个控制器的工作方式有何不同?
  • 您如何建议解决该问题?除了使用UIWindow覆盖之外,还有其他方法吗?

0 个答案:

没有答案