UIDeviceOrientation 是機器硬體的當前旋轉方向 這個你只能取值 不能設定
UIInterfaceOrientation 是你程式介面的當前旋轉方向 這個可以設定
判斷裝置現在的方向: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { UIDevice *device = [UIDevice currentDevice] ; //取得當前Device的方向,來當作判斷敘述。(Device的方向型態為Integer) switch (device.orientation) { case UIDeviceOrientationFaceUp: NSLog(@"螢幕朝上平躺"); break; case UIDeviceOrientationFaceDown: NSLog(@"螢幕朝下平躺"); break; //系統無法判斷目前Device的方向,有可能是斜置 case UIDeviceOrientationUnknown: NSLog(@"未知方向"); break; case UIDeviceOrientationLandscapeLeft: NSLog(@"螢幕向左橫置"); break; case UIDeviceOrientationLandscapeRight: NSLog(@"螢幕向右橫置"); break; case UIDeviceOrientationPortrait: NSLog(@"螢幕直立"); break; case UIDeviceOrientationPortraitUpsideDown: NSLog(@"螢幕直立,上下顛倒"); break; default: NSLog(@"無法辨識"); break; } // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支援向左橫向, YES 表示支援所有方向 }
或者 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation)) NSLog(@"橫向"); else