In my camera project, i want to know the device orientation in the case of locked screen rotation by user like the system camera.
how can i know the device orientation or unlock the screen rotation only for my project??
In my camera project, i want to know the device orientation in the case of locked screen rotation by user like the system camera.
how can i know the device orientation or unlock the screen rotation only for my project??
You may find several methods to get the current device orientation or orientation change here
Thanks for Xcoder, coreMotion helped me.
And following my code:
- (void)startMotionManager{
if (_motionManager == nil) {
_motionManager = [[CMMotionManager alloc] init];
}
_motionManager.deviceMotionUpdateInterval = 1/2.0;
if (_motionManager.deviceMotionAvailable) {
NSLog(@"Device Motion Available");
[_motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler: ^(CMDeviceMotion *motion, NSError *error){
[self performSelectorOnMainThread:@selector(handleDeviceMotion:) withObject:motion waitUntilDone:YES];
}];
} else {
NSLog(@"No device motion on device.");
[self setMotionManager:nil];
}
}
- (void)handleDeviceMotion:(CMDeviceMotion *)deviceMotion {
double x = deviceMotion.gravity.x;
double y = deviceMotion.gravity.y;
if (fabs(y) >= fabs(x)) {
if (y >= 0) {
self.deviceOrientation = UIDeviceOrientationPortraitUpsideDown;
} else {
self.deviceOrientation = AVCaptureVideoOrientationPortrait;
}
} else {
if (x >= 0) {
self.deviceOrientation = UIDeviceOrientationLandscapeRight;
}
else {
self.deviceOrientation = UIDeviceOrientationLandscapeLeft;
}
}
}