【问题标题】:device rotated but screen not stretches设备旋转但屏幕不拉伸
【发布时间】:2011-08-31 12:15:18
【问题描述】:

在我的 iphone 应用程序中,我通过以下方法返回了“是”,它可以正常工作并且屏幕正在旋转,但在横向模式下内容不适合屏幕

以下是我使用的代码

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
         return YES;

    }

以下是我的输出

如何在屏幕旋转时使屏幕内容适合屏幕尺寸,谁能帮助我,谢谢提前,

【问题讨论】:

    标签: iphone objective-c xcode device-orientation landscape-portrait


    【解决方案1】:

    当设备即将旋转时,您应该reset the views frame。这通常应该在willRotateToInterfaceOrientation 方法中完成。

    您也可以简单地使用autoResizingMask,它会在其 superView 框架发生变化时自动调整视图大小。

    // Add this line in loadView method
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | 
                                 UIViewAutoresizingFlexibleHeight;
    

    【讨论】:

    • 感谢您的回复,我已经解决了这个问题,但它不起作用 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIDeviceOrientationLandscapeRight) { self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } // 对于支持的方向返回 YES //return (interfaceOrientation == UIInterfaceOrientationPortrait);返回是; }
    • 你应该添加这一行loadView方法。
    • 有没有办法在界面生成器中做到这一点?
    【解决方案2】:

    阅读本教程:

    http://www.shinstudio.com/blog/programming/rotating-view-in-iphone-app/

    实现willRotateToInterfaceOrientation 将是解决方案

    【讨论】:

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