2012-09-21 25 views
16

Ack! Sonunda iOS 5'de çözülmüş tabbar döndürme sorunları vardı, ancak iOS 6 ve xcode bozuk şeyler içeriyor gibi görünüyor ... İşte sahip olduğum şey:UITabBarController ios'da Dönme Sorunları 6

Hedef Uygulama Özeti şunları içerir: Desteklenen Arayüz Yönleri - Port, Yatay, Yatay Sağ Uygulaması'nda

Her Tek Görünüm aşağıdaki yöntemleri vardır: sekme çubuğunun bir parçası olmayan görünümlerinde

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

- (BOOL)shouldAutorotate 
{ 
NSLog(@"am I called1?"); 
return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations{ 
    NSLog(@"am I called?"); 
    return UIInterfaceOrientationMaskPortrait; 
} 

, rotasyon engellenir. TÜM TÜM görünümlerde (5 vardır) uygulama asla CallOutorotate çağırır ve böylece döner. Desteklenen gibi görünüyorInterfaceOrientations bir kez görüntülendiğinde bir kez çağrılır, ancak görünümler arasında geçiş yaparsanız görünmüyor, çünkü NSLog aldığımdan, ancak MaskPortrait ayarını görmezden geliyor gibi görünüyor.

ben döndürmek gerekiyor, tek bir video oynatıcı görünümü var çünkü hedefin etkinleştirilmiş manzara bırakmak zorunda

(ve o kadar yapar, ince)

bu iOS 6'da bir tabbar hata mı? Görünümlerin rotasyonunu farklı şekilde devre dışı bırakmam gerekir mi? shouldautorotatetointerfaceorientation 5 Bir süre

sayesinde Zack

+0

için tüm el görünüyor hayal kırıklığı dışarı, ben SADECE sekme çubuğu uygulaması şablonu kullanarak xcode uygulamanın UITabBar bir barbones oluşturduk. (BOOL) eklemesi gerekirOutorotate {return NO; } ve - (NSUInteger) desteklenenInterfaceOrientations {return UIInterfaceOrientationMaskPortrait; } varsayılan sekme görünümünün her iki penceresine Ancak, her iki pencere hala dönüyor. Bu, iOS 6.0'da bir hata mı? TÜM pencerelerin hedeften dönmesini engellemeden bir pencereyi bir pencereden döndürmeyi engelleyebilen oldu -> özeti? Bunun için –

cevap

36

Zack için ona oldum

, bu aynı konu koştu ios büyük çalıştı. Bunun nedeni, ViewController'ınızın bir TabBar Controller veya UINavigationController içine gömülmesidir ve normal View (iOS6'da Değiştirilmiştir) yerine bu yöntemlerin çağrıları gerçekleşmektedir.

Farklı görünümlere (Kayıt İşlemi, Oturum Açma vb.) Gezinme olan tüm mod görünümlerimde bir UINavigationController içine gömülmüş bir viewController sunmakta olduğum için bu soruna girdim.

Benim basit düzeltme, bu iki yöntemi içeren UINavigationController için bir CATEGORY oluşturmaktı. Kalıcı notasyonlarımın döndürülmesini istemediğim için yine de NO'yu iade etmemeliyim. Fikriniz bu kadar basit olabilir, bir deneyin. Umarım yardımcı olur.

Bir kategori oluşturdum ve autoRotate olarak adlandırdım ve SearchAvigationController seçeneğini işaretledim. M + H dosyası aşağıdadır.

#import "UINavigationController+autoRotate.h" 

@implementation UINavigationController (autoRotate) 

-(BOOL)shouldAutorotate { 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

@end 

... ve kategori .h:

#import <UIKit/UIKit.h> 

@interface UINavigationController (autoRotate) 

-(BOOL)shouldAutorotate; 
- (NSUInteger)supportedInterfaceOrientations; 

@end 
+0

goo çözümü ve +1. –

+1

Kunani, bu harikaydı. UITabBarController + autoRotate için bir kategori yaptım ve mükemmel çalıştı! Sen bir hayat kurtarıcısın. –

+0

hey Kunani ... bu benim için çalışmıyor, bu yüzden kodumda yanlış bir şey yapmam mümkün olabilir, bu nedenle lütfen bu demo için kaynak kodu verebilir misiniz? –

7

Ben de değil birkaç Navigasyon Kontrolörleri ile bazı görünümler döndürmek için gerekli sorunu ve diğerlerini vardı. Ben bunu Viewer denetleyicisine bakmak için NavigationController söyleyerek yaptım. İşte yaptım.

RootNavigationController adlı bir UINavigationController sınıfı oluşturuyorum ve bu sınıfı storyboard'da Gezinme Denetleyicileri için Özel Sınıf olarak atadım. RootNavigationController.m'de aşağıdaki yöntemleri ekledim;

- (BOOL)shouldAutorotate { 

    return [self.visibleViewController shouldAutorotate]; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return [self.visibleViewController supportedInterfaceOrientations];  
} 

Her görünüm denetleyicisi .m dosyasında aşağıdaki yöntemleri de ekledim.

- (BOOL)shouldAutorotate { 
    //return yes or no 
} 

- (NSUInteger)supportedInterfaceOrientations{ 
    //return supported orientation masks 
} 

Bunu yapmak, görünüm denetleyicisindeki her görünüm için yönlendirmeyi ayarlamamı sağlar.

yılında benim yaptığım gibi bir sekme çubuğunu varsa

+0

pürüzsüz bir adam. gerçek pürüzsüz. Acaba Apple neden bu şekilde gitmeye karar verdi? – pir800

+5

Bu kodla karşılaştığım bir sorun, manzaradayken yalnızca portre özelliğini destekleyen bir görüntü denetleyicisine bir görüntü denetleyicisi açıyor. Hayatım boyunca, haşhaştan önce onu nasıl yeniden portre yapmaya zorlayacağımı anlayamıyorum. Durum çubuğunun yönünü değiştirmeyi ve geçerli aygıtın yönünü ayarlama konusunda eski bir hile yapmayı denedim, ancak bir etkisi olmadı (geçerli aygıtı değiştirmeye artık izin verilmiyor) – pir800

+0

Aynı sorunu yaşıyorum. @ pir800, bunu düzeltmek için hiç şansınız oldu mu? – kevboh

11

, yapmanız gereken tek şey temsilci .m dosyasına aşağıdaki eklemektir ... neyse benim için

#import "AppDelegate.h" 

//UITabBarController category to set the view rotations for ios 6 
@implementation UITabBarController (Background) 

-(BOOL)shouldAutorotate 
{ 
    //I don't want to support auto rotate, but you can return any value you want here 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    //I want to only support portrait mode 
    return UIInterfaceOrientationMaskPortrait; 
} 

@end 


/////here starts the implementation of the app delegate which is gonna be whatever you currently have on your .m delegate 

@implementation AppDelegate 

// delegate methods and other stuff 

@end 
+0

Benim için Dint çalışması – Shailesh

0

çalıştı Benim durumumda, bir UITabBarController içine yerleştirilmiş bir gezinme denetleyicisi vardı ve çalışılan şey, Kunani'nin tanımladığı gibi bir kategori oluşturuyordu, ancak UINavigationController yerine UITabBarController'ı genişletiyordu. Bu bir çekicilik :)

#import "UINavigationController+autoRotate.h" 

@implementation UINavigationController (autoRotate) 

-(BOOL)shouldAutorotate { 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

@end 

Ve .h dosyasında gibi çalıştı:

#import <UIKit/UIKit.h> 

@interface UINavigationController (autoRotate) 

-(BOOL)shouldAutorotate; 
- (NSUInteger)supportedInterfaceOrientations; 

@end 
6

Benim durumdur: 2 Navigasyon kontrolör

  • UINavigationController1:

    • UITabBarController 2 öğe vardır withRootView: ViewController1
    • UINavigationController2 withRootView: ViewController2.
    • Şimdi ViewController1 setinin seçilmesini istiyorumOtomatikleştir: NO/maskPortrait ve ViewController2 setOtomatik Döndür/MaskeTüm.

    Yani benim uygulamak: UITabBarController kategori ve UINavigationCntroller Kategori oluşturma

    UITabBarController + autoRotate.h

    @interface UITabBarController (autoRotate) 
    
    -(BOOL)shouldAutorotate; 
    - (NSUInteger)supportedInterfaceOrientations; 
    
    @end 
    

    UITabBarController + autoRotate.m

    #import "UITabBarController+autoRotate.h" 
    
    @implementation UITabBarController (autoRotate) 
    
    - (BOOL)shouldAutorotate { 
        return [self.selectedViewController shouldAutorotate]; 
    } 
    - (NSUInteger)supportedInterfaceOrientations { 
        return [self.selectedViewController supportedInterfaceOrientations]; 
    } 
    
    @end 
    
    gibi 10

    UINavigationController + autoRotate.h

    @interface UINavigationController (autoRotate) 
    
    -(BOOL)shouldAutorotate; 
    - (NSUInteger)supportedInterfaceOrientations; 
    
    @end 
    

    UINavigationController + autoRotate.m

    @implementation UINavigationController (autoRotate) 
    
    - (BOOL)shouldAutorotate { 
        return [self.visibleViewController shouldAutorotate]; 
    } 
    
    - (NSUInteger)supportedInterfaceOrientations { 
        return [self.visibleViewController supportedInterfaceOrientations]; 
    } 
    
    @end 
    

    UIViewController1.m

    - (BOOL)shouldAutorotate { 
        return NO; 
    } 
    - (NSUInteger)supportedInterfaceOrientations { 
        return UIInterfaceOrientationMaskPortrait;; 
    } 
    

    UIViewController2.m

    - (BOOL)shouldAutorotate { 
        return YES; 
    } 
    - (NSUInteger)supportedInterfaceOrientations { 
        return UIInterfaceOrientationMaskAll; 
    } 
    

    Bir işe yaradı!

  • +0

    TEŞEKKÜRLER !! aradığım şey bu! –

    -1

    Bir önceki oryantasyon durumu yeniden emin olmak için UIViewController1.m bu şey eklemek gerekir:

    (void)viewDidAppear:(BOOL)animated 
    { 
    
        [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") 
        withObject:(id)UIInterfaceOrientationPortrait]; 
    } 
    

    Mükemmel!

    +0

    setOrientation özel bir UIDevice yöntemidir ve bu kodu göndermek için reddedilebilir – Will

    0

    Bu Swift bunu yapacak

    extension UITabBarController { 
        public override func shouldAutorotate() -> Bool { 
         if let selected = self.selectedViewController { 
          return selected.shouldAutorotate() 
         } else { 
          return false 
         } 
        } 
    
        public override func supportedInterfaceOrientations() -> Int { 
         if let selected = self.selectedViewController { 
          return selected.supportedInterfaceOrientations() 
         } else { 
          return Int(UIInterfaceOrientationMask.Portrait.rawValue) 
         } 
        } 
    } 
    
    extension UINavigationController { 
        public override func shouldAutorotate() -> Bool { 
         return self.visibleViewController.shouldAutorotate() 
        } 
    
        public override func supportedInterfaceOrientations() -> Int { 
         return self.visibleViewController.supportedInterfaceOrientations() 
        } 
    }