2016-04-07 18 views
0

ViewControllerA ViewControllerB modellerini sunar.iOS - Görüntü denetleyicisinin genel olarak sunulması durumunda aygıt yönlendirmesini zorla

ViewControllerA Dikey yönde olmalıdır.

ViewControllerB, LandscapeRight yönelimi olmalıdır. ViewControllerA:

yapmam

override func shouldAutorotate() -> Bool { 
     return false 
    } 
    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
     return UIInterfaceOrientationMask.Portrait 
    } 
    override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { 
     return UIInterfaceOrientation.Portrait 
    } 

ViewControllerB

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { 
     return UIInterfaceOrientation.LandscapeRight 
    } 

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
     return UIInterfaceOrientationMask.LandscapeRight 
    } 

It çalışmaları, ama ViewControllerB kapattığınızda, ViewControllerA LandscapeRight da olur. Nasıl düzeltilir? Thx.

ÇÖZÜM:

Düzenleme AppDelegete dosyası. o ViewControllerB görevden sonra geri Portre Mod gitmek gerektiğinden

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask { 

     if self.window?.rootViewController?.presentedViewController is ViewControllerB { 

      let secondController = self.window!.rootViewController!.presentedViewController as! ViewControllerB 

      if secondController.isPresented { 
       return UIInterfaceOrientationMask.LandscapeRight; 
      } else { 
       return UIInterfaceOrientationMask.Portrait; 
      } 
     } else { 
      return UIInterfaceOrientationMask.Portrait; 
     } 
    } 
+0

Çözümünüz doğru olmakla birlikte, farklı yönlerde daha ViewControllers olacak eğer tamamen karışmaya olacaktır:

çözümdür. Çözümümü deneyebilirsin, senaryoda çalışıyor. – KlimczakM

cevap

1

Sen yılında ViewControllerA otorotasyonu izin vermeniz gerekir. Daha sonra otomatik olarak işlemez, çünkü bu ekranda yalnızca Dikey yönlendirmeye izin verirsiniz.

override func shouldAutorotate() -> Bool { 
    return true 
} 
+0

benim için çalışmıyor – phnmnn

+0

@phnmnn 'UINavigationController' arasında mı kullanıyorsunuz? Ya da sadece 'UIViewController'? – KlimczakM

+0

UINavigationController – phnmnn

İlgili konular