gpt4 book ai didi

objective-c - 自动旋转标签栏应用程序

转载 作者:行者123 更新时间:2023-12-03 16:55:41 24 4
gpt4 key购买 nike

嘿伙计们,我正在尝试自动旋转我的选项卡栏应用程序。显然,我知道大多数人会说这个问题是 return YES; 或者所有选项卡栏项目必须位于同一类中才能自动旋转。不,这对我不起作用。首先,我有 4 个选项卡栏项目,每个项目都有自己的类。我的前 2 个选项卡栏项目有 UIWebViews,第二个是 TableView ,最后一个是带有按钮的 ImageView 。现在我练习为我的第一个选项卡栏项目实现自动旋转代码,这是一个使用此代码的 UIWebView,因为 return YES; 对我不起作用:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
if (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
else
return NO;
}

在没有选项卡栏的情况下使用此代码对我有用,但是当将此代码与选项卡栏应用程序一起使用时,它对我不起作用。此外,当程序员对我说所有其他选项卡栏应用程序必须具有相同的类文件时,我不能这样做,因为我的每个选项卡栏都有自己的类文件,正如我之前所说的。

所以希望有人可以帮助我解决这种情况,以便自动旋转整个标签栏,谢谢

最佳答案

您需要在标签栏中的所有 View Controller 上返回YES

<小时/>

您的代码也可以更短,只是这样:

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

关于objective-c - 自动旋转标签栏应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5157431/

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