UIInterfaceOrientationとUIDeviceOrientationは必ずしも一致しないので注意。特定の画面の向きをサポートしていない場合や、アプリを起動してからiPhoneを回転させていない場合などに、これらの値は一致しない。画面デザインに関することはUIDeviceOrientationを使うとうまくいく場合が多い。
//インターフェースの向き
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
//デバイスの向き
UIDeviceOrientation orientation =
[[UIDevice currentDevice] orientation];
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
//デバイスの向き
UIDeviceOrientation orientation =
[[UIDevice currentDevice] orientation];
インターフェースの向きが縦か横か判定するには以下のようにする。
if(UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])){
//縦置き(Portrait)の場合だけ実行される
}else{
//横置き(Landscape)の場合だけ実行される
}
if(UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])){
//横置き(Landscape)の場合だけ実行される
}else{
//縦置き(Portrait)の場合だけ実行される
}
//縦置き(Portrait)の場合だけ実行される
}else{
//横置き(Landscape)の場合だけ実行される
}
if(UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])){
//横置き(Landscape)の場合だけ実行される
}else{
//縦置き(Portrait)の場合だけ実行される
}