2015-05-06 44 views
0

在我的應用程序的UIView,我想要啓動UIView重疊和調暗整個畫面包括UINavigationBar,代碼如下:如何顯示重疊的UINavigationBar的

- (void)showInstruction 
{ 
    self.holedView = [[JMHoledView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    [self.view addSubview:self.holedView]; 
} 

,但確實是self.holedView只能在屏幕上沒有UINavigationBar的區域變暗。我怎樣才能做到這一點?

+0

你能否提供你正在努力才達到什麼樣的照片? – faviomob

+0

添加您的視圖到'self.view.window' – NightFury

+0

對不起,我必須有10個聲望才能發佈圖像T.T –

回答

2

可以作爲一個子視圖添加視圖窗口的或導航控制器的視圖。

[self.navigationController.view addSubview:yourView]; 

OR

[[[[UIApplication sharedApplication] delegate] window] addSubview:yourView]; 

創建視圖的委託,從上海華刪除它時,需要

+0

這個工程!謝謝... –

+0

或者如評論所述,將myview添加到self.view.window;有一些差異,我試圖找出它... –

1

您可以使用變暗的透明圖像並將其設置爲導航欄的背景圖像。

比如,對於我而言,我做了阿爾法0.2的黑色透明的圖像,並將其設置爲導航背景圖像和作出的背景顏色清晰的彩色

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"black_patch.png"] 
               forBarMetrics:UIBarMetricsDefault]; 
[UINavigationBar appearance].translucent = YES; 
navController.view.backgroundColor = [UIColor clearColor]; 
0

我用這個在主窗口中添加子視圖:

[[UIApplication sharedApplication].keyWindow addSubview:view]; 
+0

謝謝,但這只是不適合我的情況... –

0

您可以添加它到窗口

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
UIView *backgrView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)]; 
backgrView.backgroundColor = [UIColor blackColor]; 
backgrView.alpha = 0.6; 
[[appDelegate window] addSubview:backgrView]; 

Try navigationBar.translucent = NO; , It is YES by default in iOS7. 


So you can add a version check like this: 

float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; 
if (systemVersion >= 7.0) 
{ 
navigationBar.translucent = NO; 
} 
相關問題