使用设备方向来实现模态视图控制器

发布于 2024-10-14 15:53:22 字数 312 浏览 2 评论 0原文

请原谅我的菜鸟问题,这是我的第一个问题,老实说,我花了相当大的努力来寻找自己的解决方案。

我有一个带有两个视图控制器的项目。主要的仅是纵向视图,第二个(子)模式视图控制器仅以横向模式呈现。我的目标是让设备的方向单独切换控制器(并向模态视图控制器提供函数调用,同时从主视图控制器传递某些 ivars),类似地,我希望将其重新定向为纵向关闭模态视图并恢复到起点。

我想这有点像苹果自己的计算器应用程序的工作原理?有人可以告诉我最符合 API 的方法吗? 非常感谢您抽出时间。

我非常希望避免模式视图上的“后退”或“完成”按钮,并且仅在可能的情况下才随设备方向来回更改

Please forgive me a noob question, its my first and i honestly expended a considerable effort searching for my own solution.

I have a project with two view controllers. the main on is a portrait view only and the second (sub) modal view controller is to present in landscape mode only. My goal is to have the orientation of the device alone switch the controllers (and to provide a function call to the modal view controller, passing on certain ivars from the main view controller at the same time) similarly I would like a reorienting to portrait to dismiss the modal view and revert to the starting point.

I imagine this is somewhat how apples own calculator app works? Can anybody give me a clue about the most API compliant way to go about this?
Thank you so much for your time.

I would very much like to avoid a 'back' or 'done' button on the modal view, and change back and forth with the device orientation only if this is at all possible

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫瑾少女 2024-10-21 15:53:22

Apple 为您想要做的事情提供了很好的解释和示例代码。请参阅 视图控制器编程指南中的创建备用景观界面

Apple has a good explanation and sample code for exactly the thing you want to do. See Creating an Alternate Landscape Interface in the View Controller Programming Guide.

抽个烟儿 2024-10-21 15:53:22

如果您为视图启用了旋转,那么在 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationuration:(NSTimeInterval)duration 中,您可以检查方向和相应的操作,如下所示:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
    {
     //check if modal viewController is already alive 
     //pop the modal if needed
    }
   else
    {
    //destory the modal if its still alive
    }
}

If you have rotation enabled for your views then in -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration You can check the orientation and the act accordingly like this:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
    {
     //check if modal viewController is already alive 
     //pop the modal if needed
    }
   else
    {
    //destory the modal if its still alive
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文