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 關注
- 851 瀏覽
添加回答
舉報