gpt4 book ai didi

iphone - 设置状态栏隐藏后不旋转

转载 作者:行者123 更新时间:2023-11-29 04:40:11 25 4
gpt4 key购买 nike

一般来说,我的应用程序只能在纵向模式下运行,但一个屏幕应该只能在横向模式下运行。所以我需要旋转 View 、隐藏状态栏并添加工具栏。当状态栏可见时,我的 View 旋转良好,但是在执行 [[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];
}

最佳答案

您发布的代码对我有用: View 显示为旋转,我可以稍后使用默认值旋转它

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

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

[super viewWillAppear:animated];

关于iphone - 设置状态栏隐藏后不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10500526/

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