轻松拍摄照片或视频,或从相册选择
🍺 作者的小费罐:https://amazon.com/hz/wishlist/ls/EE78A23EEGQB
要运行示例项目,请克隆 repo,并首先从 Example 目录运行 pod install
。
要在你的项目中使用它,请添加一个 FDTakeController
到你的视图控制器并实现
fdTakeController.didGetPhoto = {
(_ photo: UIImage, _ info: [AnyHashable : Any]) in
}
然后调用
fdTakeController.present()
完整的 API 是
/// Public initializer
public override init()
/// Convenience method for getting a photo
open class func getPhotoWithCallback(getPhotoWithCallback callback: @escaping (_ photo: UIImage, _ info: [AnyHashable : Any]) -> Void) -> <<error type>>
/// Convenience method for getting a video
open class func getVideoWithCallback(getVideoWithCallback callback: @escaping (_ video: URL, _ info: [AnyHashable : Any]) -> Void)
/// Whether to allow selecting a photo
open var allowsPhoto: Bool
/// Whether to allow selecting a video
open var allowsVideo: Bool
/// Whether to allow capturing a photo/video with the camera
open var allowsTake: Bool
/// Whether to allow selecting existing media
open var allowsSelectFromLibrary: Bool
/// Whether to allow editing the media after capturing/selection
open var allowsEditing: Bool
/// Whether to use full screen camera preview on the iPad
open var iPadUsesFullScreenCamera: Bool
/// Enable selfie mode by default
open var defaultsToFrontCamera: Bool
/// The UIBarButtonItem to present from (may be replaced by overloaded methods)
open var presentingBarButtonItem: UIBarButtonItem?
/// The UIView to present from (may be replaced by overloaded methods)
open var presentingView: UIView?
/// The UIRect to present from (may be replaced by overloaded methods)
open var presentingRect: CGRect?
/// The UITabBar to present from (may be replaced by overloaded methods)
open var presentingTabBar: UITabBar?
/// The UIViewController to present from (may be replaced by overloaded methods)
open lazy var presentingViewController: UIViewController { get set }
/// A photo was selected
open var didGetPhoto: ((_ photo: UIImage, _ info: [AnyHashable : Any]) -> Void)?
/// A video was selected
open var didGetVideo: ((_ video: URL, _ info: [AnyHashable : Any]) -> Void)?
/// The user did not attempt to select a photo
open var didDeny: (() -> Void)?
/// The user started selecting a photo or took a photo and then hit cancel
open var didCancel: (() -> Void)?
/// A photo or video was selected but the ImagePicker had NIL for EditedImage and OriginalImage
open var didFail: (() -> Void)?
/// Custom UI text (skips localization)
open var cancelText: String?
/// Custom UI text (skips localization)
open var chooseFromLibraryText: String?
/// Custom UI text (skips localization)
open var chooseFromPhotoRollText: String?
/// Custom UI text (skips localization)
open var noSourcesText: String?
/// Custom UI text (skips localization)
open var takePhotoText: String?
/// Custom UI text (skips localization)
open var takeVideoText: String?
/// Presents the user with an option to take a photo or choose a photo from the library
open func present()
/// Dismisses the displayed view. Especially handy if the sheet is displayed while suspending the app,
open func dismiss()
其他可用选项已记录在 FDTake 的 CocoaDocs 中。
FDTake.strings
翻译成更多语言使用 Swift Package Manager 将此添加到您的项目中。 在 Xcode 中,这很简单:File > Swift Packages > Add Package Dependency... 就可以了。 下面显示了旧项目的替代安装选项。
如果您已经在使用 CocoaPods,只需将“FDTake”添加到您的 Podfile
中,然后运行 pod install
。
如果您已经在使用 Carthage,只需将其添加到您的 Cartfile
中
github "fulldecent/FDTake"
然后运行 carthage update
以构建框架并将构建的 FDTake
.framework 拖到您的 Xcode 项目中。
William Entriken, github.com@phor.net
这是一个成熟的项目,除非某些内容已经成为其他应用程序中的最新技术,否则我们预计不会添加新功能。 在提出功能请求之前,请准备好引用其他应用程序的屏幕截图。
我们支持最新发布的 Xcode、Carthage、CocoaPods 和 Swift Package Manager 版本的 targets。 如果存在不兼容性,例如 CocoaPods 不支持最新版本的 Xcode,那么我们将仅支持受支持的最新发布版本/组合。 如果您想支持这些软件包的预发行版本,请打开一个 pull request,而不是一个 issue。
FDTake 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。
此项目的布局基于 https://github.com/fulldecent/swift4-module-template 如果您想更改布局,请首先更改该项目。 此外,您可能会欣赏该项目具有“recipes” - 您不只是更改代码,而是解释为什么要这样做。 作为维护者,这使我的工作变得简单得多。 以类似的方式,如果您要引入非微小的更改,如果您能参考另一个项目(如 AlamoFire),该项目已经看到并讨论了您所接触的设计挑战的类型,那将非常有帮助。)再次感谢,我们都非常感谢您的贡献。