at_yasu's blog

ロード的なことを

UIViewControllerの回転検知とsetViewControllers:animated:

まず回転検知から、

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

の「UIInterfaceOrientation」がわからなかったので、NSLogで表示させて地道な解析結果。



以下は、シミュレータを正常位の状態から回転させていった結果です。右横やら左横とありますが、「右横は右に回転」と言う意味合いです。

    //正常→右横 UIInterfaceOrientationPortrait = 右に回転 -- 
    //右横→反対 UIInterfaceOrientationLandscapeLeft = さらに右に回転 -- 
    //反対→左横 UIInterfaceOrientationPortraitUpsideDown == さらに右 -- 
    //左横→正常 UIInterfaceOrientationLandscapeRight == 更に右 -- 
    //正常→左横 UIInterfaceOrientationPortrait = 左に回転 -- 
    //左横→反対 UIInterfaceOrientationLandscapeRight = さらに左 -- 
    //反対→右横 UIInterfaceOrientationPortraitUpsideDown = さらに左 -- 
    //右横→正常 UIInterfaceOrientationLandscapeLeft = 更に左 -- 
    //正常→右横 UIInterfaceOrientationPortrait = 右
    //右横→正常 UIInterfaceOrientationLandscapeLeft = 左
    //正常→左横 UIInterfaceOrientationPortrait = 左
    //左横→正常 UIInterfaceOrientationLandscapeRight = 右

setViewControllers:animated:

例えば、A <=> B <=> C とそれぞれのViewControllerが遷移するとする。そして、Aの特別なアクションで、Bを通過させずにCに飛ばしたいとする。

その場合、下記のようにすれば良い。

// A,B,C は UIViewController の子で、このメソッドは、Aにある物とする。
NSArray *arr = [NSArray arrayWithObjects:A,B,C, nil];
[AsetViewControllers:arr, animated:YES];