gpt4 book ai didi

ios6 - iOS 6 标签栏应用 : shouldAutorotate not working

转载 作者:行者123 更新时间:2023-12-01 10:56:34 25 4
gpt4 key购买 nike

我正在使用 iOS 6 和 Xcode 4.5 在 Storyboard 中开发一个带有标签栏和一些导航 View Controller 的应用程序

通常应用程序应该支持所有界面方向,但我有两个 View 只应支持纵向模式。

所以我在 View Controller 中添加了以下代码:

-(BOOL)shouldAutorotate
{
return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}

我在 iOS 6 上开发的另一个没有 Storyboard和导航 View Controller 的应用程序可以工作,但她不行! :/

我希望有人能提供帮助,因为我发现了其他一些没有帮助的帖子...

德国致以最诚挚的问候

劳伦斯

编辑:

我也试过了——没用! :

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;

}

最佳答案

据我所知,这个问题的出现是因为 UITabBarController 和 UINavigationController 正在为 -(BOOL)shouldAutorotate 和 -(NSUInteger)supportedInterfaceOrientations 返回它们自己的默认值。

一个解决方案是通过类别(或只是子类)扩展这两个类,以便从您自己的 View Controller 中这些方法的实现中返回适当的值。这对我有用(你可以把它放到你的 App Delegate 中):

@implementation UITabBarController(AutorotationFromSelectedView)

- (BOOL)shouldAutorotate {
if (self.selectedViewController) {
return [self.selectedViewController shouldAutorotate];
} else {
return YES;
}
}

- (NSUInteger)supportedInterfaceOrientations {
if (self.selectedViewController) {
return [self.selectedViewController supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}

@end

@implementation UINavigationController(AutorotationFromVisibleView)

- (BOOL)shouldAutorotate {
if (self.visibleViewController) {
return [self.visibleViewController shouldAutorotate];
} else {
return YES;
}
}

- (NSUInteger)supportedInterfaceOrientations {
if (self.visibleViewController) {
return [self.visibleViewController supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
@end

默认情况下,所有 View Controller 将继续自动旋转。在应该只支持纵向模式的两个 View Controller 中,实现以下内容:

-(BOOL)shouldAutorotate {
return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

关于ios6 - iOS 6 标签栏应用 : shouldAutorotate not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14896904/

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