就是用CMMotionManager啦
#import <CoreMotion/CoreMotion.h>
[self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData * _Nullable accelerometerData, NSError * _Nullable error) {
if (accelerometerData.acceleration.x >= 0.75) {//home button left
_orientationNew = UIDeviceOrientationLandscapeLeft;
}
else if (accelerometerData.acceleration.x <= -0.75) {//home button right
_orientationNew = UIDeviceOrientationLandscapeRight;
}
else if (accelerometerData.acceleration.y <= -0.75) {
_orientationNew = UIDeviceOrientationPortrait;
}
else if (accelerometerData.acceleration.y >= 0.75) {
_orientationNew = UIDeviceOrientationPortraitUpsideDown;
}
else {
return;
}
}];