0

Αccording to the Apple's documentation, the image picker only supports portrait mode.

But i want my custom OverlayView to detect device Orientation, for rotate respectively the custom buttons/images i use.

Apple doing that also, on Camera App. If you rotate your device on Landscape, you'll notice that Switch Front Camera Button and Photos thumbnail, rotate itself too.

Is there any way to achieve that?

dejix
  • 1,144
  • 1
  • 12
  • 23

1 Answers1

1

Well, tried something simple on Controller that uses the imagePicker and did worked. Let me know, if you have a better solution.

func checkRotation(){
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        print("landscape")
    } else {
        print("portrait")
    }
}

override func viewDidLoad(){
    super.viewDidLoad()

    NSNotificationCenter.defaultCenter().addObserver(self,
        selector: #selector(self.checkRotation),
        name: UIDeviceOrientationDidChangeNotification,
        object: nil)

}

EDIT : After struggling with UIDevice.currentDevice().orientation I noticed that randomly didn't received rightly results of orientation. So i followed that one solution posted here on stackoverflow by using CMMotionManager. Just made some changes by using observer and async_patch.

SNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.accelerationGetOrientation), name: UIDeviceOrientationDidChangeNotification, object: nil)

func accelerationGetOrientation(){
    uMM = CMMotionManager()
    uMM.accelerometerUpdateInterval = 0.2

    uMM.startAccelerometerUpdatesToQueue( NSOperationQueue() ) { p, _ in
        if p != nil {
            if abs( p!.acceleration.y ) < abs( p!.acceleration.x ) {
                //LANDSCAPE
                dispatch_async(dispatch_get_main_queue()) {
                    //Do UI Changes
                }
            }
            else {
                //PORTRAIT
                dispatch_async(dispatch_get_main_queue()) {
                    //Do UI Changes
                }
            }
        }
    }
}
Community
  • 1
  • 1
dejix
  • 1,144
  • 1
  • 12
  • 23