0

一般来说,我的应用程序只能在纵向上工作,但一个屏幕应该只能在横向上。所以我需要旋转我的视图,隐藏状态栏并添加一个工具栏。当状态栏可见时,我的视图旋转正常,但在我执行之后[[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];
}
4

1 回答 1

1

您发布的代码对我有用:视图出现旋转,我可以稍后旋转它,并具有默认值

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

我还将在您的viewWillAppear实现中添加以下行:

[super viewWillAppear:animated];
于 2012-05-08T14:41:30.400 回答