1

私はこれについて多くのことを検索してきましたが、私を助けるものは何も見つかりません。

別の UIViewController 内に UIViewController が含まれています。親 UIViewController が回転するとき、たとえば Portrait から LandscapeLeft に、子が回転していないように見せたいと思います。ということです。親の向きに関係なく、子供が空に対して同じ向きになるようにします。ポートレートで直立したUIButtonがある場合、ボタンの右側がUIInterfaceOrientationLandscapeLeftで「上」になるようにします。

これは可能ですか?現在、私は次のような本当にひどいことをしています:

-(void) rotate:(UIInterfaceOrientation)fromOrientation: toOr:(UIInterfaceOrientation)toOrientation
{
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeRight))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeLeft))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeRight)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationLandscapeRight))
       || ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
    {

    }   
}

これは完全に無駄なコードのように思えます。さらに、私は CGAffineTransform を使用することを計画していました (ここで引用されているように: http://www.crystalminds.nl/?p=1102 )が、ビューの寸法を変更して回転後の寸法に合わせるべきかどうかについて混乱しています.

ここでの大きな悪夢は、グローバルな「方向」変数を追跡しなければならないことです。そうしないと、錯覚が失われ、ViewController が何にでも回転します。

私は本当にこれでいくつかの助けを借りることができました、ありがとう!

4

2 に答える 2

5

あなたができる最善のことは、あなたのインターフェースの向きに応じてあなたのサブビューフレームのフレームを変更することです. 次のようにできます。

 #pragma mark -
 #pragma mark InterfaceOrientationMethods

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        //self.view = portraitView;
        [self changeTheViewToPortrait:YES andDuration:duration];

    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        //self.view = landscapeView;
        [self changeTheViewToPortrait:NO andDuration:duration];
    }
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];

    if(portrait){
        //change the view and subview frames for the portrait view
    }
    else{   
        //change the view and subview  frames for the landscape view
    }

    [UIView commitAnimations];
}

お役に立てれば。

于 2010-03-22T08:12:05.823 に答える
0

私は何かに気づきました..私たちのプロジェクトにViewControllerの複数のレイヤーがあるとしましょう(他のViewControllerのサブビューをViewControllerに追加する場合のように)

willRotateToInterfaceOrientation:durationメソッドは、ViewControllerの2番目のレイヤーに対しては呼び出されません。

つまり、最上位のレイヤーから2番目のレイヤーのビューコントローラーを初期化した後、最上位のレイヤーでwillRotateToInterfaceOrientation:durationメソッドが呼び出されると、2番目のレイヤーのビューコントローラーに対してもwillRotateToInterfaceOrientation:durationを呼び出します。

于 2010-08-25T03:27:55.760 に答える