IOS中的屏幕方向更改

时间:2014-09-05 05:18:39

标签: ios screen orientation

我是IOS编程的新手。我用两个按钮创建一个新的单一视图应用程序。工作正常模式但是当旋转屏幕时它会空白

2 个答案:

答案 0 :(得分:0)

我认为你没有为横向模式启用它。只需转到项目目标 - >部署信息,然后启用横向模式的设备方向。然后使用这种方法并在那里提到你的按钮位置。

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 

if( (orientation == UIDeviceOrientationPortrait ) ||(orientation == UIDeviceOrientationPortraitUpsideDown))
{
    // portrait button positons
}

if((orientation == UIDeviceOrientationLandscapeLeft) ||(orientation == UIDeviceOrientationLandscapeRight))
{
    //landscape button positons
}

答案 1 :(得分:0)

问题可能是你没有在方向上改变两个按钮的框架。所以有两种解决方案。

  1. 您可以将autolayout应用于两个按钮,并让autolayout处理两个按钮的位置。

  2. 您可以使用以下方法以编程方式更改两个按钮的帧/位置

    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
    
    if( (orientation == UIDeviceOrientationPortrait ) ||(orientation == UIDeviceOrientationPortraitUpsideDown))
    {
      //Change frame as per **portrait** button positons
    }
    
    else if((orientation == UIDeviceOrientationLandscapeLeft) ||(orientation == UIDeviceOrientationLandscapeRight))
    {
     //Change frame as per **landscape** button positons
    }
    
  3. 您可以使用类似于自动布局的自动调整功能,但不能自动布局(功能和使用差异)。