我这里有个小问题。我在同一个 Storyboard上有两个 View Controller (MainStoryboard -> 纵向模式下的 Calc View Controller 和横向模式下的 Calc View Controller )。当我最初为 shouldAutoRotate
创建一个 bool
时,它确实旋转了,但是“现在仍然是”渲染问题,因为一些按钮等不在您期望的位置它们是,换句话说,它们在横向模式下无处不在。所以现在我已经在横向模式和主纵向模式下创建了 2 个 View Controller 。所以现在的关键是在旋转时在这两个 Controller 之间切换。
在 CalculatorViewController.m 中我有
更新
我注意到一些方法已从 iOS 6 中删除(这就是我现在使用的方法)经过一些研究我发现在 iOS 6 中“正确的方法”是这样的
@synthesize portraitView, landscapeView;
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations:toInterfaceOrientation
{
if(UIInterfaceOrientationMaskAllButUpsideDown)
{
if ( UIInterfaceOrientationPortrait )
{
self.view = portraitView;
}
else if ( UIInterfaceOrientationLandscapeLeft )
{
self.view = landscapeView;
}
}
return YES;
}
然而,尽管我认为我使用的是关于 iOS 6 的正确方法,但我仍然无法在旋转时调用正确的 View Controller
并在 CalculatorViewController.h 中
@interface CalculatorViewController : UIViewController {
IBOutlet UIView *portraitView; // declaring view - portrait
IBOutlet UIView *landscapeView; // declaring view - landscape
//rest of irrelevant code below
}
@property (nonatomic, retain) UIView *portraitView;
@property (nonatomic, retain) UIView *landscapeView;
忽略那些现在无关紧要的 2 个白色 Controller 。提交图片以显示这 2 个 View Controller
谢谢你的时间
最佳答案
我已经做过几次这样的事情,让你的 ViewController 有一个空白 View 通常更容易。然后只需将横向 View 添加为横向的主要 subview ,然后在旋转为纵向等时将其删除。如果您尝试拥有单独的 VC,那么您将拥有一团乱七八糟的状态保存代码,只是为了顺利过渡。
您甚至可以通过让两者始终是 subview 并在适当的时候显示/隐藏它们来摆弄这种设计。这会占用更多内存,但您可以制作一些不错的过渡动画。
这样一来,您所有的连接和逻辑都将在一个 VC 中,只是界面会发生变化。
关于ios - 在同一个 Storyboard上的 2 个 View Controller 之间切换,使用 willAutorotateTo 进行旋转...不起作用,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967366/