Change UIInterfaceOrientation for only one UIViewC

2020-04-30 02:06发布

问题:

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:

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;