将我的视图控制器的纵向旋转为横向和纵向模式
通常,我的应用程序以纵向模式显示除报告视图之外的所有视图。仅当我处于设置视图并将设备旋转为横向模式时,才会显示报告视图。现在,当我再次将设备旋转到纵向模式时,报告视图将关闭并显示设置视图。
In report view
> shouldAutorotateToInterfaceOrientation
return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight)||( interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
Here at settings view
shouldAutorotateToInterfaceOrientation
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight)||( interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
{
Report *report = [[Report alloc]initWithNibName:@"Report" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:report animated:YES];
[report release];
}
return YES;
}
Normally my application shows all views in portrait mode except report view. Report view shows only when I am on settings view and I rotate my device to landscape mode. Now when I rotate my device to portrait mode again, report view is dismissed and settings view is displayed.
In report view
> shouldAutorotateToInterfaceOrientation
return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight)||( interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
Here at settings view
shouldAutorotateToInterfaceOrientation
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight)||( interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
{
Report *report = [[Report alloc]initWithNibName:@"Report" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:report animated:YES];
[report release];
}
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要在 shouldRotate... 中创建视图控制器,而是在
willRotateToInterfaceOrientation:duration:
中创建视图控制器,这是您应该响应旋转的地方。在您的shouldAutorotateToInterfaceOrientation:
中,当您希望能够旋转到该方向时,只需返回 YES - 在您的情况下,看起来您想要旋转到所有方向,或除 PortraitUpsideDown 之外的所有方向。在
willRotateToInterfaceOrientation:duration:
中,您可以根据需要推送或弹出视图控制器。Don't create your viewcontroller in shouldRotate..., but in
willRotateToInterfaceOrientation:duration:
, which is where you're supposed to respond to a rotation. In yourshouldAutorotateToInterfaceOrientation:
, just return YES when you want to be able to rotate to that orientation- in your case, it looks like you want to either all orientations, or all orientations except PortraitUpsideDown.In your
willRotateToInterfaceOrientation:duration:
, you can push your viewcontroller or pop it as needed.