Как использовать dismissModalViewControllerAnimated - PullRequest
0 голосов
/ 14 марта 2012

, когда я запускаю приложение и поворачиваю iPhone в альбомной ориентации, я загружаю другое представление (представление справки).Теперь, если я перехожу в другой вид с помощью одной из кнопок, присутствующих на главном экране, и поворачиваю iPhone, открывается вид справки ... Я хотел бы знать, как выполнить загрузку вида справки только когдам в первом представлении.Вот мой код .m:

@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

РЕДАКТИРОВАТЬ:

-(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];
    }
}
}

1 Ответ

0 голосов
/ 14 марта 2012

Возможно, вы могли бы сделать это, проверив внутри вашего метода 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
        }
    }
}

Кстати, я нашелподсказка о том, как проверить, виден ли контроллер представления здесь: Как определить, является ли представление UIViewController видимым

...