10

So I currently have a camera app. I have it so it only works in portrait mode but you can still record videos and take photos in landscape mode fine. I use the following code to handle that:

videoConnection?.videoOrientation = self.orientation()

However, since the app does not register landscape mode itself you can not record the screen via quicktime in landscape (it stays portrait) (quicktime>file>record movie>choose device name)

Is there a way to fix this? I don't need to actually change the anything about the device to support landscape, I just want the ability to be able to record it that way in quicktime but nothing in the UI needs to be changed.

Jonovono
  • 1,979
  • 7
  • 30
  • 53

4 Answers4

3

You can set call beginGeneratingDeviceOrientationNotifications for UIDevice and subscribe to UIDeviceOrientationDidChangeNotification. Afterward you can use orientation property of UIDevice in your code.

Reference Apple documentation for UIDevice class for details.

Nikita Leonov
  • 5,684
  • 31
  • 37
  • Hi. Thank you. I am not quite sure how I would use this. Any examples? – Jonovono Jul 09 '15 at 02:18
  • @user2433617 Here is an answer to your request for example — http://stackoverflow.com/questions/25666269/ios8-swift-how-to-detect-orientation-change – Nikita Leonov Jul 09 '15 at 05:25
0

Try setting the call beginGeneratingDeviceOrientationNotifications for UIDevice and subscribe it to UIDeviceOrientationDidChangeNotification.

Use oreintation proporty of UIDevice.

0

What you need to do is to detect the change in orientation:

Check this apple documentation UIDevice Class Reference, for more details about that.

Here is a sample implemention in Obj-C && Swift

Community
  • 1
  • 1
0yeoj
  • 4,500
  • 3
  • 23
  • 41
0

This is what I ended up doing! Making use of the marked answer.

func orientationChanged() {
    var orient = UIDevice.currentDevice().orientation

    if orient == UIDeviceOrientation.Portrait {
        print("PORT")
                UIApplication.sharedApplication().statusBarOrientation = UIInterfaceOrientation.Portrait
    } else if orient == UIDeviceOrientation.LandscapeLeft {
        print("OR ARE YOU CRASHING")
                UIApplication.sharedApplication().statusBarOrientation = UIInterfaceOrientation.LandscapeRight
    } else if orient == UIDeviceOrientation.LandscapeRight {
        print("WHY YOU CRASHING")
                UIApplication.sharedApplication().statusBarOrientation = UIInterfaceOrientation.LandscapeLeft
    } else if orient == UIDeviceOrientation.PortraitUpsideDown {
                UIApplication.sharedApplication().statusBarOrientation = UIInterfaceOrientation.PortraitUpsideDown
    }
Jonovono
  • 1,979
  • 7
  • 30
  • 53