亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

shouldAutorotateToInterfaceOrientation在iOS 6中不起作用

shouldAutorotateToInterfaceOrientation在iOS 6中不起作用

iOS
jeck貓 2019-11-14 10:15:52
在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;    }當我搜索此定向問題時,我發現了所有這一切但對我沒有任何幫助:(請幫助.....
查看完整描述

3 回答

?
慕俠2389804

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的文章。


我希望這可以幫到你。


查看完整回答
反對 回復 2019-11-14
?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

我解決此問題的方法是,當我的應用程序在Delegate類中啟動時替換以下行


 window addSubview: navigationController.view


window.rootViewController = navigationController

進行此更改后,我的應用開始處理屏幕旋轉


查看完整回答
反對 回復 2019-11-14
?
慕桂英546537

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;    

}


查看完整回答
反對 回復 2019-11-14
  • 3 回答
  • 0 關注
  • 851 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號