デバイスの現在の向きを検出したい。
だから、私はコード行を使用しました
注: 登録していなくてもオリエンテーションが表示されます
-(IBAction) deviceOrientationChanged:(id) sender{
NSLog(@"Device Orientation= %d",[[UIDevice currentDevice] orientation]);
}
向きを変更すると、ボタン クリック イベントでデバイスの向きが取得されます。
ただし、ドキュメントには、最初に登録してから上記のコードを使用する必要があると書かれています。
注:以下のコードでは、デバイスの向きの通知を受け取るようにデバイスを登録しました
-(IBAction) deviceOrientationChanged:(id) sender{
if(![[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]){
//This statement is called very time when I click on the button. I expected to execute only once.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
NSLog(@"Device Orientation= %d",[[UIDevice currentDevice] orientation]);
}
そのため、デバイスの向きを取得するための完璧な方法を取得できません。