Спасибо за Xcoder, мне помог coreMotion.
И следующий мой код:
- (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;
}
}
}
это Безразлично 'работы, когда запирающий вращение экрана, UIDevice.currentDevice() ориентация случае все дни состояние раньше, и мы не можем захватить действие вращения этого. время. – zhiyi
CoreMotion может помочь – zhiyi