以编程方式禁用纵向锁定
Programmatically disable portrait orientation lock
在我的相机应用程序中,一切都完美无缺。如果用户 phone 未启用纵向锁定,则一切正常。
但是,如果用户启用了纵向锁定并横向录制,则视频会以纵向模式录制,但视频中的所有内容都是横向的。
有没有办法检查是否启用了纵向锁定或有什么办法可以解决这个问题?谢谢你。
您可以使用以下方法禁用纵向锁定:
- (NSUInteger)lockorientation
{
return UIInterfaceOrientationMaskPortrait;
}
有几件事。您可以在使用相机的视图控制器中覆盖 shouldAutorotate
函数,如下所示:
override func shouldAutorotate() -> Bool {
return true
}
然后您可以在他们使用完相机后再次将其设置为 false,以便保留他们的设备设置。不确定这是否是最好的方式,但这是一种方式。
另一种可能解决此问题的方法是始终检查设备方向。即使 UI 的视觉方向不自动旋转 (https://developer.apple.com/documentation/uikit/uidevice/1620053-orientation). So the following shows the possible device orientations, as per the Apple documentation (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
}
这些可能会解决您的问题。
在我的相机应用程序中,一切都完美无缺。如果用户 phone 未启用纵向锁定,则一切正常。
但是,如果用户启用了纵向锁定并横向录制,则视频会以纵向模式录制,但视频中的所有内容都是横向的。
有没有办法检查是否启用了纵向锁定或有什么办法可以解决这个问题?谢谢你。
您可以使用以下方法禁用纵向锁定:
- (NSUInteger)lockorientation
{
return UIInterfaceOrientationMaskPortrait;
}
有几件事。您可以在使用相机的视图控制器中覆盖 shouldAutorotate
函数,如下所示:
override func shouldAutorotate() -> Bool {
return true
}
然后您可以在他们使用完相机后再次将其设置为 false,以便保留他们的设备设置。不确定这是否是最好的方式,但这是一种方式。
另一种可能解决此问题的方法是始终检查设备方向。即使 UI 的视觉方向不自动旋转 (https://developer.apple.com/documentation/uikit/uidevice/1620053-orientation). So the following shows the possible device orientations, as per the Apple documentation (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
}
这些可能会解决您的问题。