2017-07-17 117 views
0

在我的相機應用程序中,一切工作都非常精確。如果在用戶手機上未啓用縱向方向鎖定,則一切正常。以編程方式禁用縱向方向鎖定

但是,如果用戶啓用了縱向方向鎖定並且他們側身錄製,則視頻會以縱向模式進行錄製,但所有內容都在視頻內側。

是否有任何方法檢查縱向方向鎖定是否啓用或以任何方式解決此問題?謝謝。

enter image description here

回答

0

有幾件事情。您可以覆蓋在視圖控制器的shouldAutorotate功能所使用的相機,像這樣:

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

然後,你可以再次將其設置爲false,一旦他們用相機完成,因此保留了他們的設備設置。不知道這是否是最好的方式,而是一種方式。

另一種可能的解決方法是簡單地檢查設備的方向。即使UI的視覺方向未自動旋轉,設備仍會檢測設備的物理方向(https://developer.apple.com/documentation/uikit/uidevice/1620053-orientation)。所以下面給出了可能的設備取向,按照蘋果的文檔(https://developer.apple.com/documentation/uikit/uideviceorientation

enum UIDeviceOrientation : Int { case Unknown case Portrait // Device oriented vertically, home button on the bottom case PortraitUpsideDown // Device oriented vertically, home button on the top case LandscapeLeft // Device oriented horizontally, home button on the right case LandscapeRight // Device oriented horizontally, home button on the left case FaceUp // Device oriented flat, face up case FaceDown // Device oriented flat, face down }

知道那些你可以檢查當前的方向是其中之一:

if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft) { ...override autorotate to true }

這些可能會解決您的問題。

0

您可以使用此方法禁用縱向方向鎖定:

- (NSUInteger)lockorientation 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 
+0

我在哪裏以及如何執行此操作。它告訴我期望的減速? –

相關問題