【问题标题】:iOS - Change view when orientation changesiOS - 方向改变时改变视图
【发布时间】:2018-06-25 01:23:27
【问题描述】:

我使用 iOS5 和故事板,我创建了两个 ViewController,一个用于纵向,一个用于横向.. 我用两个“模态segue”连接了两个视图,这是我使用的代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation))
{
    [self performSegueWithIdentifier: @"aaaa" sender: self];
}
else if (deviceOrientation == UIDeviceOrientationPortrait)
{
    [self performSegueWithIdentifier: @"ddd" sender: self];
}    

return true;

}

如果我从纵向更改为横向,它可以工作,但是当我返回纵向视图时,它会崩溃并显示“没有标识符为 'ddd' 的 segue”,但它存在。

谢谢。

【问题讨论】:

  • 您确定在界面生成器中将segue的标识符设置为ddd吗?

标签: iphone ios uiinterfaceorientation uistoryboardsegue


【解决方案1】:

我已经解决了在视图之间设置模态segue,然后使用以下代码进入实现文件:

- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
   if(self.interfaceOrientation == UIDeviceOrientationPortrait || self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown){

       [self performSegueWithIdentifier: @"aaaa" sender: self];

   } else  if(self.interfaceOrientation == UIDeviceOrientationLandscapeLeft || self.interfaceOrientation == UIDeviceOrientationLandscapeRight)
   {

       [self performSegueWithIdentifier: @"ddd" sender: self];
   }
}

ViewController 的课程(纵向和横向)。

【讨论】:

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