2017-07-17 119 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

我在哪里以及如何执行此操作。它告诉我期望的减速? –

相关问题