iOS 5 多故事板旋转
我有一个 iPad 应用程序,有 2 个视图,每个视图都有自己的视图控制器。苹果表示,他们建议 iPad 应用程序能够向各个方向旋转。我使用这种技术在旋转变化时定位故事板中的元素:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
studentNumberButton.frame = CGRectMake(30, 1, 158, 155);
studentNumberLabel.frame = CGRectMake(173, 57, 347, 43);
studentLabel.frame = CGRectMake(528, 56, 67, 43);
// Other code goes below...
我对每个视图都执行了此操作,并且它对于所有旋转都适用。然而,当我说,将 iPad 放在横向视图控制器 1 上并按下按钮以显示视图控制器 2 时,问题就出现了,视图控制器 2 效果很好,但处于纵向模式。如果我处于视图控制器 2 的横向模式并转到视图控制器 1,也会发生同样的情况。如果我处于纵向模式,则两个视图的一切都很好。
我怎样才能做到当我切换视图时,视图知道设备所在的方向并相应地旋转?
谢谢!
I have an iPad app that has 2 views each with its own View Controller. Apple states they suggest iPad apps be able to rotate in all directions. I used this technique to position the elements in my storyboard on rotation changes:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
studentNumberButton.frame = CGRectMake(30, 1, 158, 155);
studentNumberLabel.frame = CGRectMake(173, 57, 347, 43);
studentLabel.frame = CGRectMake(528, 56, 67, 43);
// Other code goes below...
I did this for each view and it works fine for all rotations. However the issue comes up when I say, have the the iPad on View Controller 1 in landscape and press a button to show View Controller 2, View Controller 2 comes up just fine but is in Portrait mode. Same happens if I am in landscape mode for View Controller 2 and go to View Controller 1. If I am in portrait mode, everything is fine for both views.
How can i make it so when I switch views, the view knows what orientation the device is in and rotates accordingly?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加一个viewWillAppear方法,如下所示:
}
You need to add a viewWillAppear method as follows:
}