12
12

More than 5 years have passed since last update.

iOSの画面回転について

Last updated at Posted at 2014-05-01

意外なところでハマったんですけど、iOSの指南書で大体はiOS5.0あたりのものが多いのでしょうか。
画面回転における制御がiOS6.0以降に変わっている事に気づかないのですよ…。
あと、DeviceOrientationで制御してるつもりでも上手くいかなかったり…。
というわけで、以下は前後比較。

iOS6.0より前
//画面回転に関する制御
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;    //全方位回転

//    if(interfaceOrientation == UIInterfaceOrientationPortrait){
//        // 通常
//        return YES;
//    }else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
//        // 左に倒した状態
//        return YES;
//    }else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight){
//        // 右に倒した状態
//        return YES;
//    }else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
//        // 逆さまの状態
//        return NO;
//    }

}
iOS6.0以降
//回転処理が存在し、可能かどうか
- (BOOL)shouldAutorotate;
{
    return YES;                                           //回転許可
}

//回転する方向の指定
- (NSUInteger)supportedInterfaceOrientations;
{
//全方位回転
    return UIInterfaceOrientationMaskAll;
////Portrait(HomeButtonが下)のみ
//      return UIInterfaceOrientationMaskPortrait;
////LandscapeLeft(HomeButtonが右)のみ
//      return UIInterfaceOrientationMaskLandscapeLeft;
////LandscapeRight(HomeButtonが左)のみ
//      return UIInterfaceOrientationMaskLandscapeRight;
////PortraitUpsideDown(HomeButtonが上)のみ
//      return UIInterfaceOrientationMaskPortraitUpsideDown;
////UpsideDown(HomeButtonが上)以外回転
//  return UIInterfaceOrientationMaskAllButUpsideDown;
////横のみ回転
//      return UIInterfaceOrientationMaskLandscape;
}
12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12