我有一个应用,我需要录制一个小视频。我需要视频的横向宽高比(16(宽)-9(高))。我尝试使用UIImagePickerController强制横向,但似乎Apple不允许它。理想情况下,我希望在横向上始终使用overlayCameraView。
到目前为止我的代码:
extension UIImagePickerController {
override open func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(self.rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
func rotated() {
if UIDevice.current.orientation.isLandscape {
self.pleaseRotateImageView.alpha = 0.0
} else {
self.pleaseRotateImageView.alpha = 1.0
}
}
按下录制视频按钮时
if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
if UIImagePickerController.availableCaptureModes(for: .front) != nil {
imagePicker.sourceType = .camera
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.allowsEditing = false
imagePicker.delegate = self
imagePicker.videoMaximumDuration = 5
imagePicker.showsCameraControls = false
//customView stuff
let customViewController = CustomOverlayViewController(
nibName:"CustomOverlayViewController",
bundle: nil
)
let customView:CustomOverlayView = customViewController.view as! CustomOverlayView
customView.frame = self.imagePicker.view.frame
present(imagePicker, animated: true, completion: {
self.imagePicker.cameraOverlayView = customView
})
} else {
let alert = SCLAlertView()
alert.showWarning("Rear camera doesn't exist", subTitle: "Application cannot access the camera.")
}
} else {
let alert = SCLAlertView()
alert.showWarning("Camera inaccessable", subTitle: "Application cannot access the camera.")
}