iPhoneやiPadで、端末を物理的に回転させずに、画面だけ回転させたいということありませんか?例えば、ターン制のゲームで、二人で向かい合ってプレイする場合などです。
デバイスの向きは読み取り専用のプロパティーで変更できません。そこで、画面全体を包含しているUIViewのtransformを設定することで画面を回転させます。後半部分はステータスバーの場所を切り替えています。ランドスケープ(横置き)の場合はこのままコピペで大丈夫です。ポートレート(縦置き)の場合は、適宜向きを書き換えてご利用ください。
-(void)flip{
self.view.transform = CGAffineTransformRotate(self.view.transform, 3.1415926535);
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
}else{
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
}
self.view.transform = CGAffineTransformRotate(self.view.transform, 3.1415926535);
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
}else{
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
}
参考
How to rotate iPad screen upside down