因此,我创建了自己的UIImagePicker,当用户单击按钮时将显示该UIImagePicker。我已经做到了,所以这个图像选择器仅显示视频。但是,当我第一次显示它时,它仍然显示,相机胶卷,然后是照片,然后当我单击照片库时,那里只有视频,正如我期望的那样。
但是我怎么只会看视频。
就像在此屏幕上一样,我希望将相册标记为视频。
这是我的图像选择器控制器代码
/// Selector Controller used to pick a video
open class ImagePickerController : UIImagePickerController, TypedRowControllerType, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
/// The row that pushed or presented this controller
public var row: RowOf<URL>!
/// A closure to be called when the controller disappears.
public var onDismissCallback : ((UIViewController) -> ())?
open override func viewDidLoad() {
super.viewDidLoad()
delegate = self
mediaTypes = [kUTTypeMovie as String]
}
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
guard let videoURL = info[UIImagePickerControllerMediaURL] as? URL else {
return
}
(row as? _VideoRow)?.videoURL = videoURL
onDismissCallback?(self)
}
open func imagePickerControllerDidCancel(_ picker: UIImagePickerController){
onDismissCallback?(self)
}
}
这是我对源类型进行的布局
public struct VideoRowSourceTypes : OptionSet {
public let rawValue: Int
public var imagePickerControllerSourceTypeRawValue: Int { return self.rawValue >> 1 }
public init(rawValue: Int) { self.rawValue = rawValue }
init(_ sourceType: UIImagePickerController.SourceType) { self.init(rawValue: 1 << sourceType.rawValue) }
public static let PhotoLibrary = VideoRowSourceTypes(.photoLibrary)
public static let All: VideoRowSourceTypes = [PhotoLibrary]
}
所以我的问题是,当我转到imagePicker时,如何使其只显示视频,而不是单击相机胶卷然后选择视频? 和 如何更改导航栏的标题以选择视频,因为此行代码不起作用
private func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
viewController.navigationItem.title = "Choose Video"
}