iPhone开发之隐藏系统状态栏

一、始终隐藏状态栏

如果在App中需要状态栏一直是隐藏着的,可以在<YOUR_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启动的那个瞬间,还是可以看到状态栏的,然后一闪即过。虽然时间很短暂,看着还是很不舒服。为了让状态栏从启动的时候就隐藏起来,可以修改<YOUR_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;
    }
     
}

 

 

posted @ 2012-04-12 22:08  FoxBabe  阅读(3184)  评论(2编辑  收藏  举报