gpt4 book ai didi

objective-c - iOS 6 无法自动旋转

转载 作者:行者123 更新时间:2023-12-03 17:34:48 25 4
gpt4 key购买 nike

在我维护的应用程序中,在纵向和纵向颠倒模式下应该发生旋转。 (所有旋转均在摘要面板中启用。)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return interfaceOrientation==UIInterfaceOrientationPortrait || interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown;
}

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

无论我如何尝试,我都无法在 ios 6 中实现旋转准确

到目前为止我尝试过的事情:

-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

-(NSInteger)supportedInterfaceOrientations{
NSInteger mask = 0;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
mask |= UIInterfaceOrientationMaskLandscapeRight;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
mask |= UIInterfaceOrientationMaskLandscapeLeft;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
mask |= UIInterfaceOrientationMaskPortrait;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
return mask;
}

我尝试将其放入我的应用程序委托(delegate)中:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortraitUpsideDown;
}

但我收到此错误:由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 返回 YES”

尝试将其放入我的委托(delegate)中:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations = UIInterfaceOrientationMaskAll;

if (self.window.rootViewController) {
UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presented supportedInterfaceOrientations];
}
return orientations;
}

我阅读了所有有关它的讨论以及 shouldAutorotateToInterfaceOrientation 的弃用,但我仍然无法让它工作。

我快要失去它了

最佳答案

我的应用程序针对的是 IOS 5。我对 IOS 5 设备使用了 shouldAutorotateToInterfaceOrientation 方法(默认情况下)。并类别 UINavigationController 来处理 IOS 6 的方向。

#import "UINavigationController+Rotation_IOS6.h"

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{

return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if([self.visibleViewController isMemberOfClass:NSClassFromString(@"SampleViewController")])
{
return UIInterfaceOrientationMaskLandscape | UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationPortrait;

}

@end

关于objective-c - iOS 6 无法自动旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15871986/

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