2011-02-06 4 views
0

私はこれを動作させるために最後の数時間を費やしてしまったので、私がしようとしていることが正しいことを知る必要はありません。それは私を怒らせる!UIViewControllerとオリエンテーションは正しい方向に向いていますか?

私の目標は、方向の変化を検出するViewControllerを持つことです。それは肖像画のときに私がプログラムで作成するコンテンツを持つUIViewをその風景に表示すると、UITableViewでの表示を示します。私は私の親のViewControllerで

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

TableDataViewController *tableDataController = [[TableDataViewController alloc] 
      initWithNibName:@"TableDataViewController"                     
        bundle:nil]; 
self.tableDataViewController = tableDataController; 
[self.view insertSubview: tableDataController.view atIndex:0]; 
[tableDataController release]; 
} 

これは、テーブルビューとそれに行くのコントローラを含む私の見解をロードします。次に、ユーザーはデバイスと機能を回転させます。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation             
duration:(NSTimeInterval)duration 
{ 
if (toOrientation == UIInterfaceOrientationPortrait) { 
    NSLog(@"PerformAnalysisViewController: Gone to Potrait"); 
} 

if ((toOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (toOrientation == UIInterfaceOrientationLandscapeRight)) { 
    NSLog(@"PerformAnalysisViewController: Gone to Landscape"); 

      // Load new view here 
      CGRect frame = [[UIScreen mainScreen] applicationFrame]; 
     UIView *horizView = [[[HorizView alloc] 
        initWithFrame:frame] autorelease]; 
     [self setView:horizView];; 
} 
} 

がトリガーになります。しかしそれは誘発しない?これは、私がviewDidLoadに挿入したSubviewにコントロールが渡されたためですか?もしそうなら、どうすれば元に戻すことができますか?私はオリエンテーションを検出してスーパービューからそれ自体を削除する必要がありますか?

それがうまくいけば、私はそれが上にあるように新しいビューを追加しますか?私はAppleのマニュアルを読んでみましたが、私はこの作業をすることはできません。

マイク

+0

shouldAutorotateToInterfaceOrientation:interfaceOrientationを実装しましたか?はいを返しますか? –

答えて

0

私は、UIの回転を処理するためにwillRotateToInterfaceOrientationメソッドを使用しています:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 
    if(interfaceOrientation == UIInterfaceOrientationPortrait || 
     interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     self.backgroundImageView.image = [UIImage imageNamed:@"vertical.png"]; 
    } 
    else { 
     self.backgroundImageView.image = [UIImage imageNamed:@"horizontal.png"]; 
    } 

} 

あなたのInfo.plistが複数の方向性をサポートし、あなたがshouldAutorotateToInterfaceOrientation実装されていることをことを、確認してください。interfaceOrientationをYESを返します。

+0

それは起動していないようです - info.pistを設定してshouldAutorotateToInterfaceOrientationでyesを返すにもかかわらず:interfaceOrientation – hydev

+0

私はそれを自分で解決しました。私はクラスファイルを削除し、何とかそれを壊さなければならなかったのです。 – hydev

関連する問題