2012-03-14 7 views
0

私はアプリケーションを昼食し、私は風景の中でiPhoneを回転させると、私は別のビュー(ヘルプビュー)を読み込みます。今、メインビューにあるボタンの1つを使って別のビューに移動し、iPhoneを回転させると、ヘルプビューが表示されます...ヘルプビューを読み込む方法を知りたいのですが、最初のビューではmです。ここに私の.mコードは次のとおりです。dismissModalViewControllerAnimated

@implementation Home 
@synthesize ruota; 
@synthesize portraitView,landscapeView; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

/* 
// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView 
{ 
} 
*/ 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(orientationChanged:)name:@"UIDeviceOrientationDidChangeNotification" 
object:nil]; 
[self performSelector:@selector (ritardo) withObject:nil afterDelay:5.0f]; 
} 


-(void)orientationChanged:(NSNotification *)object{ 
UIDeviceOrientation deviceOrientation = [[object object] orientation]; 
if (deviceOrientation == UIInterfaceOrientationPortrait) 
{ 
    [UIView beginAnimations:@"View Flip" context:nil]; 
    [UIView setAnimationDuration:0.5f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    self.view = self.portraitView; 
    [UIView commitAnimations]; 
    [self dismissModalViewControllerAnimated:YES]; 
} else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || 
deviceOrientation == UIInterfaceOrientationLandscapeRight) { 
    [UIView beginAnimations:@"View Flip" context:nil]; 
    [UIView setAnimationDuration:0.5f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    self.view = self.landscapeView; 
    [UIView commitAnimations]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 
} 

-(void) ritardo { 
ruota.image = [UIImage imageNamed:@"RuotaPerAiuto.png"];  
} 

- (void)viewDidUnload 
{ 
[self setPortraitView:nil]; 
[self setLandscapeView:nil]; 
[self setRuota:nil]; 
[super viewDidUnload]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation: 
(UIInterfaceOrientation)interfaceOrientation 
{ 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} else { 
    return YES; 
} 
} 
@end 

はEDIT:

-(void)orientationChanged:(NSNotification *)object{ 
UIDeviceOrientation deviceOrientation = [[object object] orientation]; 
if (deviceOrientation == UIInterfaceOrientationPortrait) 
{ 
    if (self.isViewLoaded && self.view.window) 
    { 
    [UIView beginAnimations:@"View Flip" context:nil]; 
    [UIView setAnimationDuration:0.5f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    self.view = self.portraitView; 
    [UIView commitAnimations]; 
    [self dismissModalViewControllerAnimated:YES]; 
    }  
} 

else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation 
== UIInterfaceOrientationLandscapeRight) 
{ 
    if (self.isViewLoaded && self.view.window) 
    { 
    [UIView beginAnimations:@"View Flip" context:nil]; 
    [UIView setAnimationDuration:0.5f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    self.view = self.landscapeView; 
    [UIView commitAnimations]; 
    [self dismissModalViewControllerAnimated:YES]; 
    } 
} 
} 

答えて

0

おそらく、あなたが最初のビューコントローラが表示されているかどうか、あなたのorientationChanged:メソッド内でチェックすることでこれを実現することができ、その後、場合にのみ、あなたのモーダルヘルプ画面を表示しますそれが本当である:

-(void)orientationChanged:(NSNotification *)object 
{ 
    UIDeviceOrientation deviceOrientation = [[object object] orientation]; 
    if (deviceOrientation == UIInterfaceOrientationPortrait) 
    { 
     // check if this view controller is visible 
     if (self.isViewLoaded && self.view.window) { 

      // then show modal help view controller 
     } 
    } 
} 

ところで私は、ビューコントローラがここに表示されているかどうかを確認する方法のヒントが見つかりました:How to tell if UIViewController's view is visible

+0

ありがとうございます。私は上のコードを編集しました。最初のビューから別のビューに移動し、景色を見せてもヘルプは表示されません。良い。しかし、私が家に戻ってきたら、景色を見ながら最後に見た景色が現れます。奇妙な行動 – Enzoses

関連する問題