首先说一下为什么用陀螺仪,很多时候当ios设备系统级别锁定方向后,我们使用ios系统的设备方向方法将不能其作用。 ios系统代码中为一下代码:
//下面代码只有在设备系统不锁定屏幕旋转是Natifications 方法才起作用。
- (void) addDeviceRotateObserver {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(rotateViews:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void) rotateViews:(NSObject *)sender {
UIDevice* device = [sender valueForKey:@"object"];
NSLog(@"%d",device.orientation);
// switch (device.orientation) {
// case UIDeviceOrientationPortrait: {
// NSLog(@"P");
// break;
// }
// case UIDeviceOrientationLandscapeLeft: {
// NSLog(@"LL");
// break;