Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用一个xib发布加载正确方向视图_Ios_Xcode_Uiview_Xib - Fatal编程技术网

Ios 使用一个xib发布加载正确方向视图

Ios 使用一个xib发布加载正确方向视图,ios,xcode,uiview,xib,Ios,Xcode,Uiview,Xib,我有一个具有两种不同视图的xib文件,一种用于纵向视图,另一种用于横向视图 在我的.m文件中,我有以下内容: -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { self

我有一个具有两种不同视图的xib文件,一种用于纵向视图,另一种用于横向视图

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

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

{
if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{

self.view = iPadLandscape;
}
else {

self.view = iPadPortrait;
}
}
当应用程序运行该特定屏幕时,我改变方向,新视图加载良好。不过,我注意到了两个问题。xib的“视图”连接到纵向视图。因此,当应用程序以纵向方式启动时,它看起来不错,但如果以横向方式启动,它仍然会加载纵向视图。但如果我把它移到纵向,再移到后面,风景就可以了

另一个问题是,如果,比方说,我在纵向启动并转到下一个屏幕,然后切换到横向模式(旋转良好),然后返回到我的主屏幕,它仍将在纵向视图中


任何想法?

在视图中明确检查当前方向也会出现,并更新您的视图

正如willRotateToOrientation不会在应用程序加载和许多其他事件上调用

- (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;
  }
}