2011-07-05 6 views
0

ビューコントローラAはのUIViewControllerは肖像回転

#pragma mark Rotation Delegate Methods 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations. 
    return YES; 
} 

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
     [landscapeChartViewController.chartImageView reloadWithUrl: 
      [NSString stringWithFormat:@"someurl",[symbol uppercaseString]]]; 

     NSLog(@"showing chart"); 
     [self presentModalViewController:landscapeChartViewController animated:NO]; 
    }  
} 

水平方向にビューコントローラBを表示した後、これが正常に動作水平方向に立ち往生。 View Controller Bは、横向きに表示されます。ここでビューコントローラBの実装です:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     NSLog(@"dismissing chart"); 
     [self.parentViewController dismissModalViewControllerAnimated:NO]; 
    } 
} 

問題は、私はビューコントローラAを表示するために戻って縦方向に行くときに、ビューコントローラAは横向きで立ち往生している、です。これをどうすれば解決できますか?

答えて

0

EDIT:

コントローラA:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
    [landscapeChartViewController.chartImageView reloadWithUrl: 
     [NSString stringWithFormat:@"someurl",[symbol uppercaseString]]]; 

    NSLog(@"showing chart"); 
    [self presentModalViewController:landscapeChartViewController animated:NO]; 
    }  
} 

コントローラB:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     NSLog(@"dismissing chart"); 
     [self.parentViewController dismissModalViewControllerAnimated:NO]; 
    } 
} 

私はあなたのコメントを読んだ後、私はこのように、willRotateToInterfaceOrientation:duration:代わりのwillAnimateRotationToInterfaceOrientationを使用しようとすることをお勧め多かれ少なかれ私のプロジェクトでは、2つの非モーダルビューの間でのみ同じです。

+0

....それが正常に動作します私のコードの一部です。残念ながら、このコードを実装すると、View Controller Bはポートレートモードに切り替えるときに解除されません。 –

+0

私の編集をご覧ください。 – sergio

+0

これも正しく動作しません。 View Controller Bは、ポートレートモードに切り替えるときに解除されません。 –

0

willAnimateRotationToInterfaceOrientation:からdidRotateFromInterfaceOrientation:にコードを移動し、toInterfaceOrientationの代わりにself.interfaceOrientationを使用します。

0

View Controller Bは、横向きに表示されます。ここでビューコントローラBの実装です:

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    //戻りYESサポートの向きについては、YESを返す 。

}

- (無効)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation時間:(NSTimeInterval)期間{

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
    NSLog(@"dismissing chart"); 
    [self dismissModalViewControllerAnimated:NO]; 
} 

}

0

あなたは、関数willRotateToInterfaceOrientationを実施しましたか?また、通知センターを使用して親ビューコントローラにモーダルビューコントローラが回転していることを通知してから、[self dismissModalViewControllerAnimated:YES]

0

私はいつもdidRotateFromInterfaceOrientationに私の方向ロジックを書きます。ここ はあなたが正しく、私の問題を理解

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     [connectCoverLockUnlockSwitch setFrame:CGRectMake(250,6,51,31)]; 
     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){ 

      [connectCoverLockUnlockSwitch setFrame:CGRectMake(400,6,51,31)]; 
      [self.tableView reloadData]; 
     } 
     else if (orientation == UIDeviceOrientationPortraitUpsideDown || orientation == UIDeviceOrientationPortrait){ 

     [connectCoverLockUnlockSwitch setFrame:CGRectMake(250,6,51,31)]; 

}}

else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)  { 
      UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];   

     if (orientation == UIDeviceOrientationUnknown || orientation == UIDeviceOrientationFaceUp) { 

//return; 

    } 
     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) { 
       [connectCoverLockUnlockSwitch setFrame:CGRectMake(570,6,51,31)]; 

       [self.tableView reloadData]; 
     } 

    else if (orientation == UIDeviceOrientationPortraitUpsideDown || orientation == UIDeviceOrientationPortrait) 
     { 
      [connectCoverLockUnlockSwitch setFrame:CGRectMake(330,6,51,31)]; 
      [self.tableView reloadData]; 

      } 
      } 
関連する問題