MWCamera 1.0.0

MWCamera 1.0.0

Woody Jean-Louis 维护。



MWCamera 1.0.0

MWCamera

CI Status Version License Platform

MWCamera 是一个轻盈的框架,它有助于为 ios 构建强大的相机应用程序!此框架也受到 SwiftyCam 的启发 ✊🏽。

🎙功能

  • 易于使用
  • 支持 iOS11.2+
  • 图像捕捉
  • 视频捕捉
  • 手动设置图像质量
  • 前置和后置摄像头
  • 前后闪光灯
  • 切换摄像头时录制
  • 录制时捕捉图像
  • 手动变焦
  • 手动对焦
  • 背景音频支持
  • 完全可定制的
  • 通用(iPhone 和 iPad)
  • 简单的 Swift 语法
  • 轻量级易读的代码库

📲安装

MWCamera 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'MWCamera'

🌚示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

🤓如何使用

使用 MWCamera 非常简单。

🤨📝先决条件

如果您不知道,Apple 需要将 NSCameraUsageDescriptionNSMicrophoneUsageDescription 关键字添加到应用程序的 info.plist 中。示例

<key>NSCameraUsageDescription</key>
<string>To Capture Photos and Videos</string>
<key>NSMicrophoneUsageDescription</key>
<string>To Record Audio</string>

🥳 入门

如果您从 Cocoapods 安装 MWCamera,请确保在文件顶部导入模块。

import MWCamera

要开始使用 MWCamera,请从 MWCameraViewController 继承。

class CameraViewController: MWCameraViewController

一旦处理了摄像头和麦克风权限,您现在可以通过调用来配置 AVCaptureSession

self.reconfigureSession()

在此之后,您可以自由地开始添加自己的配置到 AVCaptureDevice 中,如下所示

if let device = self?.captureDevice {
    do {
        try device.lockForConfiguration()
        if device.isFocusModeSupported(.continuousAutoFocus) {
            device.focusMode = .continuousAutoFocus
        }

        if device.isSmoothAutoFocusSupported {
            device.isSmoothAutoFocusEnabled = true
        }

        if device.isExposureModeSupported(.continuousAutoExposure) {
            device.exposureMode = .continuousAutoExposure
        }

        if device.isWhiteBalanceModeSupported(.continuousAutoWhiteBalance) {
            device.whiteBalanceMode = .continuousAutoWhiteBalance
        }

        if device.isLowLightBoostSupported {
            device.automaticallyEnablesLowLightBoostWhenAvailable = true
        }

        device.unlockForConfiguration()
    } catch {
        print("[mwCamera]: Error locking configuration")
    }
}

然后再调用

self.beginSession()

就只需这些步骤即可启动您的摄像头会话!💪🏾

此外,self.reconfigureSession()不会添加音频输入和输出。这些元素在录制前添加到会话中,录制后移除,以模仿 Snapchat/Instagram 中的功能。

为了捕获媒体,MWCamera 具有以下功能

func startRecording() {}

func stopRecording() {}

func cancelRecording() {}

func capturePhoto() {}

要获得实时提示,请设置 MWCameraDelegate。对于照片捕获提示,MWCamera 已实现 AVCapturePhotoCaptureDelegate,因此您可以覆盖这些函数。请确保调用 super 以保持 MWCamera 正确运行。

还有一件事!

MWCameraButton 是一个投入视图,使得设置instagram/snapchat摄像头应用变得更加容易。只需三行即可

let captureButton = MWCameraButton()
self.register(captureButton)
view.addSubview(captureButton)

📚文档

即将推出...😅?

📋支持的操作系统和 SDK 版本

  • iOS 11.2+
  • Swift 4.2+

📬下一步

  • 更好的文档
  • 从按钮平滑缩放
  • 不那么侵入性和可定制的日志
  • 类似Snap/Insta滤镜的AR示例
  • 支持iPadOS吗?
  • 支持MacOS吗?

❤️贡献

这是一个开源项目,因此您可以自由贡献。如何做到这一点?

  • 打开一个问题
  • 通过电子邮件发送反馈。
  • 提出自己的修复方案、建议,并通过拉取请求进行更改。

查看所有贡献者链接

👨🏽‍💻 作者

woodyjl, [email protected]

👮🏾‍♀️ 许可证

MIT License

Copyright (c) 2019 woodyjl <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

MWCamera 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。