【问题标题】:Issue loading correct orientation UIView on load using one xib使用一个 xib 在加载时加载正确的方向 UIView 问题
【发布时间】:2013-01-21 16:11:29
【问题描述】:

我有一个带有两个不同视图的 xib 文件,一个用于纵向,一个用于横向。

在我的 .m 文件中,我有以下内容:

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{
if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{

self.view = iPadLandscape;
}
else {

self.view = iPadPortrait;
}
}

当应用程序运行该特定屏幕并且我更改方向时,新视图加载正常。我注意到了两个问题。 xib 的“视图”连接到纵向视图。因此,当应用程序以纵向启动时,它看起来不错,但如果以横向启动,它仍会加载纵向视图。但是,如果我将其移至纵向并返回横向视图,则加载正常。

另一个问题是,如果我以纵向启动并转到下一个屏幕,然后更改为横向模式(旋转正常),然后返回我的主屏幕,它仍然是纵向视图。

有什么想法吗???

【问题讨论】:

    标签: ios xcode uiview xib


    【解决方案1】:

    在 viewWillAppear 中明确检查当前方向并更新您的视图。

    因为 willRotateToOrientation 不会在应用程序加载和许多其他事件中调用

    【讨论】:

      【解决方案2】:
      - (void)viewWillAppear:(BOOL)animated
      {
        [super viewWillAppear:animated];
        NSUInteger orientation = [UIDevice currentDevice].orientation;
        switch (orientation) {
          case UIDeviceOrientationLandscapeLeft:
          case UIDeviceOrientationLandscapeRight:
            // self.view == my landscape view
            break;
          case UIDeviceOrientationPortrait:
          case UIDeviceOrientationPortraitUpsideDown:
            // self.view == my portrait view
            break;
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-27
        • 1970-01-01
        • 2015-04-08
        • 1970-01-01
        • 2014-12-19
        • 1970-01-01
        • 2011-10-11
        • 1970-01-01
        相关资源
        最近更新 更多