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
}
}
}
}
}