1.隐藏某个页面的状态栏
再视图加载到窗口之前添加该方法
- (BOOL)prefersStatusBarHidden
{
return YES;//iOS7.0中隐藏状态栏
}
一、始终隐藏状态栏
如果在App中需要状态栏一直是隐藏着的,可以在AppDelegate的application:didFinishLaunchingWithOptions:
函数中进行设置,比如下面这段示意代码可以让状态栏以淡出的方式隐藏起来:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
// Add the view controller‘s view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
二、APP启动时隐藏状态栏
用了上面的方法之后,App在运行过程中,状态栏确实被隐藏起来了,但是我发现在App启动的那个瞬间,还是可以看到状态栏的,然后一 闪即过。虽然时间很短暂,看着还是很不舒服。为了让状态栏从启动的时候就隐藏起来,可以修改-Info.plist。如 果在Xcode中修改,在根结点Infomation Property List下面新加一项“Status bar is initially hidden”(不用手动输入,可以直接在下拉菜单中选取)。这是个BOOL类型的键值,将Value栏中的复选框勾选上即可。
三、在运行程序过程中隐藏状态栏
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
flag = 0;
UIView *view = [[UIControl alloc]init];
view.backgroundColor = [UIColor redColor];
[(UIControl *)view addTarget:self action:@selector(touchpicture:) forControlEvents:UIControlEventTouchUpInside];
[view setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:view];
}
-(void)touchpicture:(UIView *)sender{
if (flag == 0) {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
flag = 1;
}else {
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
flag = 0;
}
}
原文地址:http://www.cnblogs.com/z-j-w/p/4173555.html