gpt4 book ai didi

当我使用 UIImagePickerController 允许编辑时 iOS 7 StatusBar 问题

转载 作者:可可西里 更新时间:2023-11-01 03:33:04 26 4
gpt4 key购买 nike

我研究了相关的 iOS 7 状态栏维护,但是我在使用 UIImagePickerController 时遇到了问题。允许编辑窗口在顶部栏显示 20 像素的空间。

我使用代码,首先我在 info.plist 中将 UIViewControllerBasedStatusBarAppearance 设置为 NO 并设置委托(delegate)方法:

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, 20, self.window.frame.size.width, self.window.frame.size.height);

background = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, self.window.frame.size.width, 20)];
background.backgroundColor =[UIColor redColor];
[background setHidden:NO];
}

在我的 home view controller 中没有效果,所以我在我的 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, 20, self.view.frame.size.width,screenHeight-20);
self.view.bounds = CGRectMake(0, 0, self.view.frame.size.width, 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 时,允许编辑窗口显示如下:

Enter image description here

我尝试使用此解决方案在存在 UIImagePickerController 时隐藏状态栏:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}

并在ViewWillApear中显示状态条码。

我得到了这种类型的结果:

Enter image description here

我哪里做错了,我该如何解决?

最佳答案

尝试一下:

-(BOOL)prefersStatusBarHidden { return YES; }

它会隐藏状态栏。

在 iOS 7 上,如果你想使用 setStatusBarHidden: ,你需要在 info.plist 中将 View controller-based status bar appearance 设置为 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, 20, self.view.frame.size.width,screenHeight-20);
self.view.bounds = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

UIWindow *defaultWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:0];

defaultWindow.frame = CGRectMake(0,20,320,548);
defaultWindow.bounds = CGRectMake(0,20,320,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 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21059145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com