如何在整个屏幕上添加图像

时间:2013-08-30 11:13:35

标签: iphone ios objective-c ios6 uiimageview

我正试图将覆盖图像放在整个iPhone屏幕上(通过导航标签栏)来自viewDidLoad,但没有任何反应。
< / p>

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;

这是我想要获得的结果: enter image description here

2 个答案:

答案 0 :(得分:4)

由于UIWindowUIView的子类,您还可以将子视图添加到关键窗口。
这些子视图将显示在任何视图控制器上方。

UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview:imageView];

答案 1 :(得分:0)

imageView.frame = [[UIScreen mainScreen] applicationFrame];
[self.navigationController.view addSubview: imageView];