2

ポートレートモードでは別のUIViewControllerを表示し、ランドスケープモードでは別のUIViewControllerを表示するUIViewControllerを備えたアプリケーションを作成しました。

風景に行くときは、物を描いたり配置したりするので、風景の座標を取得する必要があります。以下は、iPhoneが回転したときに新しいビューをトリガーするコードです。以下のコードは、このビューがロードされる方法です。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)x
  duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(x)) 
{
    NSLog(@"Going Portrait");

} else if (UIInterfaceOrientationIsLandscape(x)) 
{
    NSLog(@"Going Landscape");
    if (activeView != [graphViewController view]) 
    {
        [containerView addSubview:[graphViewController view]];  
    }
}
}

私の問題は、

-(void)loadView {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
NSLog(@"GraphViewController: Screenbounds %@", NSStringFromCGRect(screenBounds));
}

GraphViewControllerが返すと、次のように生成されます 。GraphViewController:Screenbounds {{0、0}、{320、480}}

これは風景の共演ではないので、私の絵は正しくありません。[UIScreenmainScreen]境界]を呼び出すときにGraphViewControllerが正しい座標を持つようにするにはどうすればよいですか。?

どうもありがとう

マイク

4

1 に答える 1

1

あなたの問題はあなたが構築した階層にあると思います。2番目のViewControllerを追加すると、(横向きであっても)縦向きモードであると見なされます。私はあなたの問題を解決するのは実装することだと思います

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation

メインのviewcontrollerとgraphviewcontrollerの両方のメソッド。

しかし、これは下がるのに良い道ではないと思います。さまざまなインターフェイスを表示するためにuiviewsだけでなくuiviewcontrollersを使用している特定の理由はありますか?

まっすぐなUIViewに移動して、次のようなことを行うことができる場合

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)x
  duration:(NSTimeInterval)duration
{
   if (UIInterfaceOrientationIsPortrait(x)) 
   {
       NSLog(@"Going Portrait");

   } 
   else if (UIInterfaceOrientationIsLandscape(x)) 
   {
       NSLog(@"Going Landscape");
       if (activeView != graphView) 
       {
           containerView = graphView;
           //OR
           [containerView addSubview:graphView];
       }
   }
}

長期的にはあなたのほうが良いと思いますが、あなたの選択です。

于 2011-02-15T02:11:10.720 に答える