我使用了代码,首先我在info.pList中将UIVIEwControllerBasedStatusBarappearance设置为NO并设置委托方法:
Appdelegate.h
@property (retain,nonatomic) UIWindow *background;
Appdelegate.m
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { [application setStatusbarStyle:UIStatusbarStylelightContent]; self.window.clipsToBounds =YES; self.window.frame = CGRectMake(0,20,self.window.frame.size.wIDth,self.window.frame.size.height-20); self.window.bounds = CGRectMake(0,self.window.frame.size.height); background = [[UIWindow alloc] initWithFrame: CGRectMake(0,20)]; background.backgroundcolor =[UIcolor redcolor]; [background setHIDden:NO];}
在我的家庭视图控制器中没有任何效果,所以我放入了我的home vIEwController,一种用于更改状态栏背景颜色的方法:
-(voID)vIEwWillLayoutSubvIEws{if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { self.vIEw.clipsToBounds = YES; CGRect screenRect = [[UIScreen mainScreen] bounds]; CGfloat screenHeight = screenRect.size.height; self.vIEw.frame = CGRectMake(0,self.vIEw.frame.size.wIDth,screenHeight-20); self.vIEw.bounds = CGRectMake(0,self.vIEw.frame.size.height); UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userIsMale"]) { [tempWindow setBackgroundcolor:[UIcolor colorWithRed:(46.0/255.0) green:(134.0/255.0) blue:(255.0/255.0) Alpha:1]]; } else { [tempWindow setBackgroundcolor:[UIcolor colorWithRed:(246.0/255.0) green:(26.0/255.0) blue:(113.0/255.0) Alpha:1]]; } [[UIApplication sharedApplication] setStatusbarStyle:UIStatusbarStylelightContent];}
现在,当我呈现UIImagePickerController时,允许编辑窗口显示如下:
我尝试使用此解决方案为隐藏状态栏,同时呈现UIImagePickerController:
- (voID)navigationController:(UINavigationController *)navigationController willShowVIEwController:(UIVIEwController *)vIEwController animated:(BOol)animated{ [[UIApplication sharedApplication] setStatusbarHIDden:YES];}
并在VIEwWillApear中显示状态条形码.
我得到了这种结果:
我在哪里做错了,我该如何解决这个问题?
解决方法 尝试一下:-(BOol)prefeRSStatusbarHIDden { return YES; }
它会隐藏状态栏.
在iOS 7上,如果要使用setStatusbarHIDden :,则需要在info.pList中将基于VIEw控制器的状态栏外观设置为NO.
我希望它会给你一些暗示.
编辑:
我发现了问题.
这是第一次在vIEwWillAppear上显示homeVIEwController时的日志:
(lldb) po [[UIApplication sharedApplication] windows]<__NSArrayM 0x8a74560>(<UIWindow: 0x8e33360; frame = (0 20; 320 548); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x8e348b0>; layer = <UIWindowLayer: 0x8e3c6e0>>,<UIWindow: 0x8c1db40; frame = (0 0; 320 20); gestureRecognizers = <NSArray: 0x8c1e170>; layer = <UIWindowLayer: 0x8c1da80>>)
这是解雇imagePicker并调用vIEwWillAppear后的日志:
(lldb) po [[UIApplication sharedApplication] windows]<__NSArrayM 0x8c1a700>(<UIWindow: 0x8e33360; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8e348b0>; layer = <UIWindowLayer: 0x8e3c6e0>>,<UIWindow: 0x8c1db40; frame = (0 0; 320 20); gestureRecognizers = <NSArray: 0x8c1e170>; layer = <UIWindowLayer: 0x8c1da80>>,<UITextEffectsWindow: 0x8c53380; frame = (0 0; 320 568); hIDden = YES; opaque = NO; gestureRecognizers = <NSArray: 0x8c538a0>; layer = <UIWindowLayer: 0x8c53520>>)
默认窗口大小已更改.这就是状态栏无法显示的原因.
我编辑了这样的代码,它对我有用:
- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; // Do any additional setup after loading the vIEw,typically from a nib. // [[UIApplication sharedApplication] setStatusbarHIDden:YES]; if(OVER_IOS7){ [self.navigationController.navigationbar setTranslucent:NO]; }}- (voID)dIDReceiveMemoryWarning{ [super dIDReceiveMemoryWarning]; // dispose of any resources that can be recreated.}- (voID)vIEwWillAppear:(BOol)animated{ [super vIEwWillAppear:animated]; [[UIApplication sharedApplication] setStatusbarHIDden:NO withAnimation:UIStatusBaranimationSlIDe];}-(voID)vIEwWillLayoutSubvIEws{ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { self.vIEw.clipsToBounds = YES; CGRect screenRect = [[UIScreen mainScreen] bounds]; CGfloat screenHeight = screenRect.size.height; self.vIEw.frame = CGRectMake(0,screenHeight-20); self.vIEw.bounds = CGRectMake(0,self.vIEw.frame.size.height); UIWindow *defaultwindow = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; defaultwindow.frame = CGRectMake(0,320,548); defaultwindow.bounds = CGRectMake(0,548); UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userIsMale"]) { [tempWindow setBackgroundcolor:[UIcolor colorWithRed:(46.0/255.0) green:(134.0/255.0) blue:(255.0/255.0) Alpha:1]]; } else { [tempWindow setBackgroundcolor:[UIcolor colorWithRed:(246.0/255.0) green:(26.0/255.0) blue:(113.0/255.0) Alpha:1]]; } [[UIApplication sharedApplication] setStatusbarStyle:UIStatusbarStylelightContent]; }}- (IBAction)showImagePicker:(ID)sender{ UIImagePickerController *picker = [[UIImagePickerController alloc] init]; [picker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum]; [self presentVIEwController:picker animated:YES completion:^{ [[UIApplication sharedApplication] setStatusbarHIDden:YES withAnimation:UIStatusBaranimationSlIDe]; }];}总结
以上是内存溢出为你收集整理的我在使用UIImagePickerController时出现iOS 7 StatusBar问题允许编辑全部内容,希望文章能够帮你解决我在使用UIImagePickerController时出现iOS 7 StatusBar问题允许编辑所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)