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

时间:2013-09-05 10:36:48

标签: ios ipad ios7 ios-simulator

我在Xcode 4.0中开发了我的应用程序(仅支持横向支持)并成功升级到每个新的IOS,但是使用ios 7,因为我们知道状态栏正在进行新的更改,在视图顶部的transulant bar如下图所示< / p>

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

但是我通过将plconist中的viewcontrollerbasedstatusappearance参数值更改为NO并且将窗口原点x坐标值更改为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;
}

在具有如下所示视图的loginviewcontroller中,我使用loadview方法覆盖控制器视图,如下所示,对于您的信息,我将其更改为直接使用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}}

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

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

所以请让我知道如何处理这个以支持ios 6&amp; 7尽快。谢谢。

1 个答案:

答案 0 :(得分:1)

我会在UIViewController的{​​{1}}视图上附上观察者:

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 } } removeObserver。这样,您始终可以使状态栏背景与当前外观保持同步。