使用下面的代码->
添加UIWindow *anotherWindow; 作为类属性(强引用)或ivar
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear: animated];
UIWindow *window =[UIApplication sharedApplication].keyWindow;
window.frame=CGRectOffset(window.frame, 0, 40);//move down the keyWindow.so navigation bar and views will come down
// add another window on top.
anotherWindow =[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
anotherWindow.windowLevel =UIWindowLevelStatusBar;
anotherWindow.hidden=NO;
UIView*view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
view.backgroundColor =[UIColor greenColor];
[anotherWindow addSubview:view];
}
方法2->
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear: animated];
UIWindow *window =[UIApplication sharedApplication].keyWindow;
[window.subviews enumerateObjectsUsingBlock:^(UIView* obj, NSUInteger idx, BOOL *stop) {
obj.frame=CGRectOffset(obj.frame, 0, 40);
}];
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
view.backgroundColor =[UIColor greenColor];
[self.view.window addSubview:view];
}
但是在关闭这个viewController之后,对于method1不要忘记重置keyWindow的框架并移除anotherWindow。对于method2,重置keyWindow的子View的frames。
对于方法 2->
在 viewdisappear 时重置 keyWindow 的子视图的框架(viewController 移除)。
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
UIWindow *window =[UIApplication sharedApplication].keyWindow;
[[window.subviews lastObject] removeFromSuperview];
[window.subviews enumerateObjectsUsingBlock:^(UIView* obj, NSUInteger idx, BOOL *stop) {
obj.frame=CGRectOffset(obj.frame, 0, -40);
}];
}