Change UIInterfaceOrientation for only one UIViewC

2020-04-30 01:15发布

I have an iPhone app with structure like "Navigation controller with table -> next view controller with table -> QLPreviewController". By tap in cell of table in first view controller(with navigation controller) appears new view controller with another table, by tap in cell of it shows QLPreviewController.

For example: In first table there are Groups, in second table - Documents of selected Group, and QLPreviewController for previewing selected Document.

Every ViewController in my app must to appear only in Portrait(not upside) orientation, but QLViewController must also support Landscape(left and right).

I'm setting flag canRotate to YES before QLPreviewController appear. In AppDelegate if canRotate == YES I'm return YES for any Orientation, to rotate QLPreviewController. QLPreviewControllerDelegate in method previewControllerWillDismiss:(QLPreviewController *)controller sets flag canRotate back to NO. But if orientation was Landscape before QLPreviewController dismiss, all of my ViewControllers stay in Landscape orientation...

How can I rotate ViewController back to Portrait orientation in WillDismiss method?

1条回答
ゆ 、 Hurt°
2楼-- · 2020-04-30 02:13

What I did on my application (its more or less like yours) was:

1) Set shouldRotate Yes for both screens.

2) For the first view set the following mask:

return UIInterfaceOrientationMaskPortrait

For the second View put:

return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
查看更多
登录 后发表回答