设置状态栏隐藏后无旋转

时间:2012-05-08 14:24:04

标签: iphone objective-c ios xcode

一般来说,我的应用只能在人像中使用,但一个屏幕应仅在横向上。所以我需要旋转我的视图,隐藏状态栏并添加工具栏。当状态栏可见时,我的视图旋转正常,但在执行[[UIApplication sharedApplication] setStatusBarHidden:YES]后,我看不到旋转..这是代码:

- (void) viewWillAppear:(BOOL)animated
{
    //[[UIApplication sharedApplication] setStatusBarHidden:YES];

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);
    [self.view setTransform:landscapeTransform];

    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.view.autoresizesSubviews = YES;
    self.view.bounds  = CGRectMake(0.0, 0.0, 480.0, 320.0);

    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 20, 480, 40)];
    [[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"BarBg"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 100, 30)];
    label.text = @"asdasd";
    [toolBar addSubview:label];

    [self.view addSubview:toolBar];

    self.gallery.backgroundColor = [UIColor redColor];
}

1 个答案:

答案 0 :(得分:1)

您发布的代码对我有用:视图显示为已旋转,我可以稍后将其旋转为默认

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

我还会在viewWillAppear实施中添加以下内容:

[super viewWillAppear:animated];