[英]iOS - Change view when orientation changes
I use iOS5 with storyboards, I created two ViewController, one for the portrait orientation and one for the landscape.. I connected the two views with two "modal segue" and this is the code that I used: 我将iOS5与情节提要板一起使用,创建了两个ViewController,一个用于纵向,一个用于横向。我将两个视图与两个“模态选择”连接起来,这是我使用的代码:
- (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;
}
If I change from portrait to landscape it works but when I return to portrait view it crashes with "has no segue with identifier 'ddd'" but it exists. 如果我从纵向更改为横向,则可以使用,但是当返回纵向视图时,它会崩溃并显示为“没有标识符为'ddd'的segue”,但它存在。
Thanks. 谢谢。
I have resolved setting a modal segue between the views and then into the implementation file with this code: 我解决了在视图之间设置模式选择的问题,然后使用以下代码将其设置到实现文件中:
- (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];
}
}
Course for both the ViewController (portrait and landscape). ViewController的课程(纵向和横向)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.