【问题标题】:ios6 rotation problemsios6旋转问题
【发布时间】:2012-11-19 05:30:02
【问题描述】:

我正在将我的应用程序转换为 ios6,但我遇到了旋转问题。 谁能帮我旋转设备时会调用哪些方法

【问题讨论】:

    标签: ios6 screen-rotation


    【解决方案1】:
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval)duration 
    {
        [self doLayoutForOrientation:toInterfaceOrientation]; 
    }
    
    
    - (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation { 
    if (UIInterfaceOrientationIsPortrait(orientation)) 
    {
    //set the frames here
    }
    else 
    {
    //set the frames here
    } 
    }
    

    这些是 ios 6 中的新方法,您可以在其中根据方向设置框架。希望对你有用。

    【讨论】:

      【解决方案2】:

      - (BOOL) shouldAutorotate -(NSUInteger)supportedInterfaceOrientations

      这些是 iOS 6 中添加的新功能。

      【讨论】:

      • 你是否在使用第三方 UI 框架,例如three20 之类的?
      • 如果不查看无法正常旋转的页面代码,我将无法回答您的问题。
      【解决方案3】:
       -(NSUInteger)supportedInterfaceOrientations
      
      {
          return UIInterfaceOrientationMaskAll;
      }
      
      -(void)viewWillLayoutSubviews
      {
      if([self interfaceOrientation] == UIInterfaceOrientationPortrait||[self interfaceOrientation] ==UIInterfaceOrientationPortraitUpsideDown)
          {
           //set the frames here
          }
          else if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
          {
            //set the frames here
          }
      }
      

      最好用这个,每次你改变设备的方向时,上面的方法都会调用。

      【讨论】:

        【解决方案4】:

        使用这些方法处理旋转

        -(BOOL) shouldAutorotate
        {
            return NO;
        }
        
        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            return UIInterfaceOrientationIsLandscape(interfaceOrientation);
        }
        

        如果某些视图在旋转并且您不希望 UIImagePickerController 之类的,只需创建一个子类并覆盖第一个方法。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-06-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多