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