Gire para disparar Segue no iOS 6
Pergunta
Eu tenho um storyboard que possui um controlador de barra de guias.Quando o dispositivo gira, quero passar para uma tela diferente, ou seja,não mostra o mesmo layout lateralmente, mas mostra algo completamente diferente.
No iOS 5 consegui isso com o seguinte código no UITabBarControllerDelegate
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[self performSegueWithIdentifier: @"toGraph" sender: self];
}
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
No iOS 6 esse método não é mais chamado.Todos os métodos que posso ver lidam com quando o visualizar é girado, mas não quando o dispositivo é girado.
Desde já, obrigado.
Solução
Então, realmente, eu não deveria estar procurando por um visualizar rotação, mas sim uma dispositivo rotação.Depois de descobrir a classe UIDevice, consegui usar o código de exemplo AlternateViews (basta procurar AlternateViews no Documentation Organizer) para obter tudo o que precisava.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.delegate = self;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
// We must add a delay here, otherwise we'll swap in the new view
// too quickly and we'll get an animation glitch
[self performSelector:@selector(showGraphs) withObject:nil afterDelay:0];
}
- (void)showGraphs
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self performSegueWithIdentifier: @"toGraph" sender: self];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
Outras dicas
A rotação automática mudou no iOS 6.Aqui está um tópico nos fóruns de desenvolvimento da Apple sobre o assunto: https://devforums.apple.com/thread/166544?tstart=30
Aqui estão mais alguns tópicos:http://www.buzztouch.com/forum/thread.php?tid=41ED2FC151397D4AD4A5A60¤tPage=1
https://www.buzztouch.com/forum/thread.php?fid=B35F4D4F5EF6B293A717EB5&tid=B35F4D4F5EF6B293A717EB5
A postagem mais relevante para o seu problema parece ser a seguinte:
Funcionou... para aplicativos com guias, substituiu esta linha no appDelegate:[self.window addSubview:[self.rootApp.rootTabBarController visualização]];
com isso:[self.window.rootViewController = visualização self.rootApp.rootTabBarController];
E para obter aplicativos sem guias, substitua esta linha:[self.window addSubview:[self.rootApp.rootNavController visualização]];
com isso:[self.window.rootViewController = visualização self.rootApp.rootNavController];