gpt4 book ai didi

xcode - shouldAutorotateToInterfaceOrientation在iOS 6中不起作用

转载 作者:行者123 更新时间:2023-12-03 09:01:38 25 4
gpt4 key购买 nike

在iOS 6中,shouldAutorotateToInterfaceOrientation无法正常工作,但在iOS 5.0和5.1中可以正常工作。
对于iOS 6我需要更改什么?这是我的代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([[[SampleApplicationAppDelegate instance].callInfoDictionary valueForKey:IS_CHAT] isEqualToString:NO_RESPONSE])
{
int nAngle = 0;
BOOL bRet = NO;

switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
nAngle = 90;
bRet = YES;
NSLog(@".......Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);

_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);

NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
break;

case UIInterfaceOrientationPortraitUpsideDown:
nAngle = 270;
bRet = YES;
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;

case UIInterfaceOrientationLandscapeLeft:
nAngle = 0;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;

case UIInterfaceOrientationLandscapeRight:
nAngle = 180;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;

default:
break;
}
return bRet;
}
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return YES;
return NO;
}
当我搜索此定向问题时,发现的只是 thisthis,但对我没有任何帮助:(
请帮忙 .....

最佳答案

编辑:发生这种情况是因为Apple已更改了管理UIViewController方向的方法。在iOS6中,方向处理方式有所不同。在中,不推荐使用iOS6 shouldAutorotateToInterfaceOrientation方法。 View Controller (例如UINavigationController)不咨询其子级来确定是否应自动旋转。默认情况下,将应用程序和 View Controller 的受支持的界面方向设置为iPad的UIInterfaceOrientationMaskAll和iPod的idit_code。

如果要将特定的 View 更改为所需的方向,则必须执行某种子类或类别,并重写自动旋转方法以返回所需的方向。

将此代码放在您的根 View Controller 中。这将帮助UIInterfaceOrientationMaskAllButUpsideDown确定其方向。

  //RotationIn_IOS6 is a Category for overriding the default orientation.

@implementation UINavigationController (RotationIn_IOS6)

-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end

现在,您需要在viewController中实现以下方法(在iOS6中引入)以进行定向
- (BOOL)shouldAutorotate
{
//returns true if want to allow orientation change
return TRUE;


}
- (NSUInteger)supportedInterfaceOrientations
{
//decide number of origination tob supported by Viewcontroller.
return UIInterfaceOrientationMaskAll;


}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//from here you Should try to Preferred orientation for ViewController
}

并将您的代码放入下面的方法中。每当设备方向改变时
该方法将被称为:
 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)  interfaceOrientation duration:(NSTimeInterval)duration
{
if([[[SampleApplicationAppDelegate instance].callInfoDictionary valueForKey:IS_CHAT] isEqualToString:NO_RESPONSE])
{
int nAngle = 0;
BOOL bRet = NO;

switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
nAngle = 90;
bRet = YES;
NSLog(@".......Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);

_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);

NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
break;

case UIInterfaceOrientationPortraitUpsideDown:
nAngle = 270;
bRet = YES;
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;

case UIInterfaceOrientationLandscapeLeft:
nAngle = 0;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;

case UIInterfaceOrientationLandscapeRight:
nAngle = 180;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;

default:
break;
}
}

编辑:检查您的窗口,您需要在窗口上将 Controller 添加为 UIViewController而不是像下面的 rootViewController
self.window.rootViewController=viewController;

有关更多信息, idiom是有关iOS6.0 Beta 2 OTA的文章。

我希望这可以帮到你。

关于xcode - shouldAutorotateToInterfaceOrientation在iOS 6中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12577879/

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