2016-03-31 84 views
2

我有一個使用AVCapturesession捕獲圖像的應用程序,我有一個單獨的View Controller,裏面有一個UIView,我在這個視圖中運行會話。修復橫向模式下的旋轉問題

當我的應用程序在縱向模式下加載時,它全部都是好的,它打開了全屏,並旋轉到橫向模式,它仍然是全屏,因爲我的視圖用於捕捉圖像,我不允許只旋轉UIView正在捕捉圖像一切正常。

唯一的問題是,當我的應用程序在橫向模式下打開時,它不是全屏,一旦我將它旋轉到縱向,它將獲得全屏,然後再回到橫向,它仍然是全屏。

我該如何解決這個問題,或者有沒有辦法強制你的iOS應用總是以縱向模式打開,然後讓它旋轉?

回答

1

我面臨同樣的問題。您應該在您的應用程序委託類中實現此方法。這裏是example.Hope這是你需要的。

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window 
{ 
    if([window.rootViewController isKindOfClass:[HRMHomeViewController class]]) 
    { 
     id homeViewController = (HRMHomeViewController*)window.rootViewController; 
     if ([[homeViewController presentedViewController] 
      isKindOfClass:[HRMCapturedScreenViewController class]]) 
      return UIInterfaceOrientationMaskPortrait; 
    } 
    return UIInterfaceOrientationMaskAll; 
} 

你的相機層的這個方法幀會根據方向旋轉

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
             duration:(NSTimeInterval)duration 
{ 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation 
              duration:duration]; 
    self.captureManager.cameraLayer.frame = self.videoView.bounds; 
} 

有在UINavigationController方法從而可以help.Here是雙向或使UINavigationController類別或繼承它。

- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController 
- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController