如题,代码如下:
if motionManager.deviceMotionAvailable {@H_404_8@
motionManager.deviceMotionUpdateInterval = 1.0@H_404_8@
let queue = NSOperationQueue()@H_404_8@
motionManager.startDeviceMotionUpdatesToQueue(queue,withHandler: {@H_404_8@
motion,error in@H_404_8@
let x = motion?.gravity.x@H_404_8@
let y = motion?.gravity.y@H_404_8@
if fabs(y!) >= fabs(x!) {@H_404_8@
if y >= 0 {@H_404_8@
// UIDeviceOrientationPortraitUpsideDown;@H_404_8@
} else {@H_404_8@
// UIDeviceOrientationPortrait;@H_404_8@
}@H_404_8@
} else {@H_404_8@
if x >= 0 {@H_404_8@
// UIDeviceOrientationLandscapeRight;@H_404_8@
} else {@H_404_8@
// UIDeviceOrientationLandscapeLeft;@H_404_8@
}@H_404_8@
}@H_404_8@
@H_404_8@
}@H_404_8@
)@H_404_8@
} else {@H_404_8@
print("Device motion is not available")@H_404_8@
}@H_404_8@