-2

I am trying to put overlay image over whole iPhone screen (over navigation and tabbar also) from viewDidLoad but nothing happens.

self.imageView = [[UIImageView alloc]
                              initWithImage:[UIImage imageNamed:@"overlayimage.png"]];
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
    [window.rootViewController.view addSubview: imageView];

UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    recognizer.delegate = self;
    [imageView addGestureRecognizer:recognizer];
    imageView.userInteractionEnabled =  YES;
    self.imageView = imageView;

This is the result that I am trying to get: enter image description here

1110
  • 7,829
  • 55
  • 176
  • 334

2 Answers2

4

Since UIWindow is a subclass of UIView, you can also add subviews to the key window.
These subviews will appear above any view controller.

UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview:imageView];
s1m0n
  • 7,825
  • 1
  • 32
  • 45
0
imageView.frame = [[UIScreen mainScreen] applicationFrame];
[self.navigationController.view addSubview: imageView];
iPatel
  • 46,010
  • 16
  • 115
  • 137