2013-03-19 25 views
8

En son SDK ile bir iOS uygulaması geliştiriyorum.Yatay yönelim ancak dikey çerçeve değerleri?

Peyzaj sağ yönelimini benzersiz yönlendirme olarak ayarlıyorum ve viewController görünümü hakkında bir sorum var.

Bu benim kodudur:

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

Ve bu olsun günlüğü geçerli:

Neden alıyorum bu değerler:

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

Sorum yaklaşık {{0, 0}, {320, 568}} nedir?

Doğru değerler {{0, 0}, {568, 320}} olacaktır.

+0

tarafından yerine sizin ViewController üzerinde değişiklik değiştirin Uygulama hala dikey iken görüntülenir. –

+0

Programı simülatörle test ettim ve yatay olarak oryantasyonda görünüyor. Ve evet, bu tam ekran uygulaması. – VansFannel

+0

Cihaz yönlendirme değişikliklerini dinlememelisiniz. 'UIViewController', yönelim değişikliklerini dinlemek için uygun yöntemlere sahiptir. Kayıt kodunuzu bu uygun yöntemlere ekleyin. DidRotateFromInterfaceOrientation: veya viewDidLayoutSubviews özelliğini deneyin. – rmaddy

cevap

3

Çerçeve röntgenlerinin yönlendirme değişikliğine tepki vermediğine inanıyorum.

DÜZENLEME: Özgün çözümüm ihtiyaçlarınız için çok karmaşıktı. Geçerli yönlendirmeyi doğru olarak buluyorsanız, manzara modundaysanız, rect'in genişliğini yalnızca yükseklik olarak yorumlayın.

+0

Ben de öyle düşünüyorum. Cevabınız için teşekkürler. – VansFannel

+1

Bu sorunun cevabına bir bakın: http://stackoverflow.com/questions/2686882/incorrect-frame-window-size-after-re-orientation-in-iphone. Çerçeve yerine sınırlar kullanmak daha iyidir. – VansFannel

+1

Ah, çok havalı! Bu konuda arama yaparken bu cevabı bulamadım. Koduma geri döneceğim ve bunun orada çalışıp çalışmadığını göreceğim. Kesinlikle daha zarif. – drewmm

1

Çerçevede ne olduğunu göstermek ve ciltlemek için bu özümü ekleyin.

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

Ve bu bana seni mi:

Bunları üç yöntem ekledik

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}} 

Bound değişiklikleri viewDidLayoutSubviews: üzerinde. yerine self.view.frame ait

0

Kullanım self.view.bounds

0

benim tahminim onun tam ekran VideoController sensin

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

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

Merhaba Soner, cevabımı ne düzenliyorsunuz? – bhaveshvirani63

İlgili konular