2013-03-19 21 views
8

Sto sviluppando un'applicazione iOS con l'ultimo SDK.Orientamento orizzontale ma valori fotogramma verticale?

Ho impostato Orientamento orizzontale come orientamento univoco disponibile e ho una domanda sulla vista viewController.

Questo è il mio codice:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(deviceOrientationDidChange:) 
               name:UIDeviceOrientationDidChangeNotification 
               object:nil]; 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != AVCaptureVideoOrientationLandscapeRight); 
} 

- (void)deviceOrientationDidChange:(NSNotification*)notification 
{ 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if (orientation == AVCaptureVideoOrientationLandscapeLeft) 
     NSLog(@"Orientation: Landscape Left"); 
    else if (orientation == AVCaptureVideoOrientationLandscapeRight) 
     NSLog(@"Orientation: Landscape Right"); 
    NSLog(@"FRAME: %@", NSStringFromCGRect(self.view.frame)); 
} 

e questo è il registro che ottengo:

Orientation: Landscape Right 
FRAME: {{0, 0}, {320, 568}} 
Orientation: Landscape Right 
FRAME: {{0, 0}, {320, 568}} 

La mia domanda riguarda {{0, 0}, {320, 568}}:

Perché ricevo questi valori?

Penso che i valori corretti sarebbero {{0, 0}, {568, 320}}.

+0

la mia ipotesi è che è un VideoController fullscreen voi stanno visualizzando, mentre l'app è ancora in verticale. –

+0

Ho testato il programma con il simulatore e appare in orientamento orizzontale. E sì, è un'app a schermo intero. – VansFannel

+0

Non si dovrebbero ascoltare i cambiamenti di orientamento del dispositivo. 'UIViewController' ha metodi appropriati per l'ascolto delle modifiche all'orientamento dell'interfaccia. Aggiungi il tuo codice di registrazione con i metodi appropriati. Prova 'didRotateFromInterfaceOrientation:' o 'viewDidLayoutSubviews'. – rmaddy

risposta

3

Credo che i frame frame non reagiscano al cambio di orientamento.

MODIFICA: la mia soluzione originale era eccessivamente complicata per le vostre esigenze. Se stai cercando correttamente l'orientamento corrente, interpreta la larghezza del retto come l'altezza se ti trovi in ​​modalità orizzontale.

+0

Questo è quello che penso. Grazie per la tua risposta. – VansFannel

+1

Dai uno sguardo alla risposta a questa domanda: http://stackoverflow.com/questions/2686882/incorrect-frame-window-size-after-re-orientation-in-iphone. È preferibile utilizzare i limiti anziché il frame. – VansFannel

+1

Ah, molto bello! Non ho trovato quella risposta quando stavo cercando su questo problema. Tornerò al mio codice e vediamo se funziona qui. È decisamente più elegante. – drewmm

1

Aggiungo questa soluzione per mostrare cosa succede con frame e rilegato.

ho aggiunto questi tre metodi:

- (void) viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
     CGRect bounds = [view bounds]; 
     NSLog(@"FRAME: %@", NSStringFromCGRect(view.frame)); 
     NSLog(@"BOUNDS: %@", NSStringFromCGRect(bounds)); 
} 

- (void)deviceOrientationDidChange:(NSNotification*)notification 
{ 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if (orientation == AVCaptureVideoOrientationLandscapeLeft) 
     NSLog(@"1. Orientation: Landscape Left"); 
    else if (orientation == AVCaptureVideoOrientationLandscapeRight) 
     NSLog(@"1. Orientation: Landscape Right"); 
    NSLog(@"1. FRAME: %@", NSStringFromCGRect(self.view.frame)); 
    NSLog(@"1. BOUNDS: %@", NSStringFromCGRect(self.view.bounds)); 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if (orientation == AVCaptureVideoOrientationLandscapeLeft) 
     NSLog(@"2. Orientation: Landscape Left"); 
    else if (orientation == AVCaptureVideoOrientationLandscapeRight) 
     NSLog(@"2. Orientation: Landscape Right"); 
    NSLog(@"2. FRAME: %@", NSStringFromCGRect(self.view.frame)); 
    NSLog(@"2. BOUNDS: %@", NSStringFromCGRect(self.view.bounds)); 
} 

- (void)viewDidLayoutSubviews 
{ 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if (orientation == AVCaptureVideoOrientationLandscapeLeft) 
     NSLog(@"3. Orientation: Landscape Left"); 
    else if (orientation == AVCaptureVideoOrientationLandscapeRight) 
     NSLog(@"3. Orientation: Landscape Right"); 
    NSLog(@"3. FRAME: %@", NSStringFromCGRect(self.view.frame)); 
    NSLog(@"3. BOUNDS: %@", NSStringFromCGRect(self.view.bounds)); 
} 

e questo è quello che ottengo:

FRAME: {{0, 0}, {320, 568}} 
BOUNDS: {{0, 0}, {320, 568}} 
3. Orientation: Landscape Right 
3. FRAME: {{0, 0}, {320, 568}} 
3. BOUNDS: {{0, 0}, {568, 320}} 
1. Orientation: Landscape Right 
1. FRAME: {{0, 0}, {320, 568}} 
1. BOUNDS: {{0, 0}, {568, 320}} 
1. Orientation: Landscape Right 
1. FRAME: {{0, 0}, {320, 568}} 
1. BOUNDS: {{0, 0}, {568, 320}} 

modifiche Bound in viewDidLayoutSubviews:.

0

Utilizzare self.view.bounds invece di self.view.frame

0

Si prega di cambiare il cambiamento sul tuo viewController

SKScene * scene = [MyScene sceneWithSize:skView.bounds.size]; 

sostituire con

SKScene * scene = [MyScene sceneWithSize:CGSizeMake(skView.frame.size.height, skView.frame.size.width)]; 
+0

Ciao Soner, cosa modifichi la mia risposta? – bhaveshvirani63

Problemi correlati