UIImagePickerController以横向录制video
我们如何强制UIImagePickerController控制器仅在横向模式下录制video?
我知道这个class应该用于人像logging,但是我需要把它放在风景中。
发现了几个类似的问题,但没有任何解决scheme适用于我(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
它几乎可以工作,但是在录制过程中我看到一些控制和video方向错误的奇怪行为(结果video是好的)。
1)开始。 取消和录制button在正确的位置,但其他控制错误。 和video旋转。
2)录音。 定时器和video是错误的。
3)录制完成。 都好! 结果video是正确的。
你有什么想法?
更新我需要在录制过程中以横向locking屏幕。
你需要实现一个自定义的UIImagePickerController
。 为此,您需要将imagepicker的属性showsCameraControls
设置为FALSE。
self.mImagePickerController.showsCameraControls = NO; self.mImagePickerController.wantsFullScreenLayout = YES;
一旦你这样做,没有默认的控件将被你看到。 您需要设置自定义button开始/停止录制和翻转相机等
现在,您可以使用开始/停止方法来录制video:
当一个人点击开始录制时,
[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
这是调用方向更改的代理。 您可以使用特定类别的对象调用其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)您需要检查翻转相机button的点击事件的条件。
2)AppDelegate.h:声明你的类的对象,你录制你的video,并创build一个属性。 在这里我使用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
是在logging类的viewWillAppear
中设置的一个flag
。 在viewDidUnload
中将其设置为false
。 或者可以viewWillAppear
另一个类的出现。
3)我已经使用cameraviewcontroller.m只是作为一个例子。 它反映你的录音class。 同样在您的录像类的shouldAutorotate
方法中,如果检测到的方向是纵向,则返回NO。 这种方式的用户界面不会改变,你可以保持只在横向的用户界面。
试试这可能会帮助你
- (BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; } - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); }
它会工作… 🙂