Push UIViewController with different orientation to previous

转自:http://stackoverflow.com/questions/6695837/push-uiviewcontroller-with-different-orientation-to-previous

参考:http://stackoverflow.com/questions/15947349/how-to-handle-different-orientations-in-ios/16022631#16022631

It makes no sense to use a UINavigationController push transition to present a view in a different orientation. Which way round would the navigation bar / toolbar be?

Presenting a modal view controller is the right way to go about this. If this causes the status bar to become hidden, make sure yourModalViewController.wantsFullScreenLayout is NO.

 

Using -[UIDevice setOrientation:] is a private API, and will get your application rejected. See this question.

What you ask is not possible using public API and is also not recommended from HIG standpoint. What is supported and you should implement, is modal presentation of the different view controllers with different supported interface orientation. This is why the default implementation of UINavigationController is to always rotate; it assumes all view controllers have the same supported interface orientations.

Take for example video playback on iPhone. Open the video apps (that comes with iOS). The root view controller only supports portrait orientation. However, start a video, and a modal view controller pops up which only supports landscape interface orientations. This seems exactly the behavior you wish to achieve.

This is why preferredInterfaceOrientationForPresentation is not called. preferredInterfaceOrientationForPresentation only gets called when using presentViewController:animated:.

A small gotcha, if you require a navigation bar in each stage of your scene, you will need to enclose each modal view controller with a navigation controller. You can then pass the required data in prepareForSegue: by accessing topViewController of the navigation controller object in the segue.

Here is an example project which behaves correctly according to your requirements (or at least will give you ideas how to implement):

http://www.mediafire.com/?zw3qesn8w4v66hy

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值