gpt4 book ai didi

iphone - UIImagePickerController 横向录制视频

转载 作者:技术小花猫 更新时间:2023-10-29 10:27:46 25 4
gpt4 key购买 nike

我们如何强制 UIImagePickerController Controller 只在横向模式下录制视频?

我知道这个类应该用于纵向录制,但我需要横向录制。

发现了几个类似的问题,但没有任何解决方案适合我(iOS 6.1)。

例如,观察设备方向对我不起作用(这个答案 - https://stackoverflow.com/a/2147584/775779)

如果我像下面这样实现 UIImagePickerController 类别:

#import "UIImagePickerController+NonRotating.h"

@implementation UIImagePickerController (NonRotating)

- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}

@end

它几乎可以工作,但我看到一些控件有一些奇怪的行为,并且在录制过程中视频方向错误(结果视频没问题)。

1) 开始。取消和录音按钮在正确的位置,但其他控件在错误的位置。并且视频是旋转的。 enter image description here

2) 录音。定时器和视频是错误的。 enter image description here

3) 录制完成。都好!结果视频是正确的。

enter image description here

你有什么想法吗?

更新我需要在录制过程中横向锁定屏幕。

最佳答案

您需要实现自定义 UIImagePickerController。为此,您需要将 imagepicker 的属性 showsCameraControls 设置为 FALSE。

self.mImagePickerController.showsCameraControls = NO;
self.mImagePickerController.wantsFullScreenLayout = YES;

执行此操作后,您将看不到任何默认控件。您需要设置自定义按钮以开始/停止录制和翻转相机等。

现在,您可以使用开始/停止方法来录制视频:

当点击开始录制时,

[self.mImagePickerController startVideoCapture];

停止,

[self.mImagePickerController stopVideoCapture];

要跟踪相机之间的切换,您可以使用标志

if (self.mImagePickerController.cameraDevice == UIImagePickerControllerCameraDeviceRear)
{
self.mImagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
isFrontCamera = YES;
}
else
{
self.mImagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
isFrontCamera = NO;
}

您可以根据需要在方向更改时设置控件。AppDelegate.m

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

这是在方向改变时被调用的委托(delegate)。您可以使用特定类的对象来调用其 shouldAutorotate 方法并根据方向设置相机控制位置。

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
[self.objController shouldAutorotate];
return UIInterfaceOrientationMaskAll;
}

现在在 cameraviewcontroller.m 里面

-(BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice]orientation];

if(interfaceOrientation == UIInterfaceOrientationPortrait)
{
// your controls setup
}
else
{
// view accordingly for landscape
}
}

我已尝试涵盖所有要点。如果您有任何困惑,请告诉我。希望对您有所帮助:)

1) 您需要检查翻转相机按钮点击事件的条件。

2) AppDelegate.h:声明一个类的对象,您可以在其中录制视频并创建一个属性。此处我使用 CameraViewController 作为示例。

CameraViewController *objController;

现在在 AppDelegate.m 中:

self.objController = [[CameraViewController alloc]initWithNibName:@"CameraViewController" bundle:nil];

现在使用此实例调用 shouldAutorotate 方法,如上所示。并返回横向:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(isOptionScreenActive == YES)
{
[self.shareController shouldAutorotate];
return UIInterfaceOrientationMaskLandscape;
}
else
{
[self.anotherController shouldAutorotate];
return UIInterfaceOrientationMaskPortrait;
}
}

这里的isOptionScreenActive是在录制类的viewWillAppear中设置的flag。在 viewDidUnload 中将其设置为 false。或者可能是另一个类的 viewWillAppear

3) 我以 cameraviewcontroller.m 为例。它反射(reflect)了您的录音等级。同样在您的视频录制类的shouldAutorotate 方法中,如果检测到的方向是纵向,则返回NO。这样 UI 就不会改变,并且您可以将 UI 保持为横向。

关于iphone - UIImagePickerController 横向录制视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15377120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com