gpt4 book ai didi

ios - 如何使用 ios 7 beta 6 横向左方向处理 ipad 中的状态栏方向

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:42 24 4
gpt4 key购买 nike

我在 Xcode 4.0 中开发了我的应用程序(仅支持横向)并成功升级到每个新的 IOS,但是我们知道在 iOS 7 中状态栏有一个新的变化, View 顶部的转换栏如下图所示

Image with fullscrenn view and statusbar on top of that in ios 7

但我通过将 plist 中的 viewcontrollerbasedstatusappearance 参数值更改为 NO 以及将窗口原点 x 坐标 vlaue 更改为 20 像素(为什么 x 坐标意味着,我的应用程序强制以横向启动)解决了这个问题,它在横向正确方向上工作。结果如下图所示,代码在这里

 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{

self.window = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
if (DEVICE_IS_IPHONE || DEVICE_IS_IPHONE5)
{
[UIApplication sharedApplication].statusBarHidden=YES;
}
else if(DEVICE_IS_IPAD)
{
[UIApplication sharedApplication].statusBarHidden=NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds=YES;
self.window.frame=CGRectMake(self.window.frame.origin.x+20, self.window.frame.origin.y, self.window.frame.size.width-20, self.window.frame.size.height);
}
}
mLoginController = [[LoginViewController alloc]init];
mNavigationController = [[UINavigationController alloc ] initWithRootViewController:mLoginController];
self.window.rootViewController = mNavigationController;
[self.window addSubview:[mNavigationController view]];
[self.window makeKeyAndVisible];
[mLoginController release];
return YES;
}

并且在具有如下所示 View 的 loginviewcontroller 中,我正在使用 loadview 方法覆盖 Controller View ,如下所示,为了您的信息,我将其更改为直接使用 viewdidload,即使发生了同样的问题。

-(void)loadView{    
CGSize theSize = CGSizeMake(1, 1);
CGRect theFrameRect = [UtilityMethods getAbsoluteFrameForSize:theSize];//i will get the exact
screen size based on device
UIView *theLoginView = [[UIView alloc]initWithFrame:CGRectMake(0, 40, theFrameRect.size.width,
theFrameRect.size.height)];
self.view = theLoginView;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
self.view.backgroundColor = [UIColor blackColor];
}

Image with normal view as in ios 6 after resolving and the statusbar frame value is like this {{0-y, 0-x}, {20-h, 1024-w}}

但是如果我再次向左旋转,状态栏将出现在 View 的顶部,状态栏的框架位于底部,如下图所示。您可以在下图中观察底部的黑色 View 我希望状态栏的窗口框架。

with status bar frame as {{748-y, 0-x}, {20-h, 1024-w}}

所以请让我知道如何处理这个问题以尽快支持 ios 6 和 7。在此先感谢。

最佳答案

我会在 UIViewController 的 View 的 bounds 上附加一个观察者:

- (void) viewDidLoad
{
[super viewDidLoad];
[self.view addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionNew context:NULL];
}

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self.view && [keyPath isEqualToString:@"bounds"]) {
//redraw your status bar background
}
}

然后在deallocremoveObserver。这样您就可以始终使状态栏背景与当前外观保持同步。

关于ios - 如何使用 ios 7 beta 6 横向左方向处理 ipad 中的状态栏方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18634057/

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