3 回答
TA贡献1719条经验 获得超6个赞
之所以发生这种情况,是因为Apple改变了管理Orientation的方式UIViewController。在iOS6中,方向处理方式有所不同。在iOS6中,该 shouldAutorotateToInterfaceOrientation方法已弃用。视图控制器(例如UINavigationController)不咨询其子级来确定是否应自动旋转。默认情况下,UIInterfaceOrientationMaskAll针对iPad 习惯用语和UIInterfaceOrientationMaskAllButUpsideDowniPhone习惯用语,将应用程序和视图控制器的受支持的界面方向设置为。
如果要将特定的视图更改为所需的方向,则必须执行某种子类或类别,并重写自动旋转方法以返回所需的方向。
将此代码放在您的根视图控制器中。这将有助于UIViewController确定其方向。
//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;
}
}
编辑:检查您的窗口,您需要在窗口上添加控制器,rootViewController而不是addSubview如下所示
self.window.rootViewController=viewController;
有关更多信息,这里是有关iOS6.0 Beta 2 OTA的文章。
我希望这可以帮到你。
TA贡献2021条经验 获得超8个赞
我解决此问题的方法是,当我的应用程序在Delegate类中启动时替换以下行
window addSubview: navigationController.view
与
window.rootViewController = navigationController
进行此更改后,我的应用开始处理屏幕旋转
TA贡献1848条经验 获得超10个赞
我解决了这个问题,只是用这个
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(![AppDelegate instance])
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
if([[[AppDelegate 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);
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"6.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending)
{
// OS version >= 6.0
NSLog(@"ami iOS 6 er device");
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
}
else
{
// OS version < 6.0
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
}
NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
NSLog(@"-->%s %d",__FUNCTION__,__LINE__);
break;
}
case UIInterfaceOrientationPortraitUpsideDown:
{
nAngle = 270;
bRet = YES;
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"6.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending)
{
// OS version >= 6.0
NSLog(@"ami iOS 6 er device");
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
}
else
{
// OS version < 6.0
_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;
}
- 3 回答
- 0 关注
- 811 浏览
添加回答
举报