SmartImageView 0.1.3

SmartImageView 0.1.3

Manuel Bulos 维护。



SmartImageView

CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,并先从 Example 目录中运行 pod install

要求

iOS 11.0 *

安装

SmartImageView 通过 CocoaPods 提供。要安装它,简单地将以下行添加到您的 Podfile 中

pod 'SmartImageView'

用法

import UIKit

class ViewController: UIViewController {

    // Works programmatically or using the interface builder
    @IBOutlet weak var smartImageView: SmartImageView!
    
    fileprivate let image = UIImage(named: "Sample1")

    override func viewDidLoad() {
        super.viewDidLoad()
        smartImageView.delegate = self
        smartImageView.searchForFaces(on: image)
    }
}

SmartImageViewDelegate

import UIKit

@available(iOS 11.0, *)
@objc public protocol SmartImageViewDelegate: class {

    /// Asks the delegate for a view object to display in every face found.
    @objc optional func smartImageView(_ smartImageView: SmartImageView, viewForFaceIn frame: CGRect) -> UIView

    /// Sent after SmartImageView finishes searching for faces.
    @objc optional func smartImageView(_ smartImageView: SmartImageView, numberOfFacesFound: Int)

    /// Sent if an error was found at any time during the task.
    @objc optional func smartImageView(_ smartImageView: SmartImageView, encountered error: Error)

}

SmartImageViewDelegate 使用方法

extension ViewController: SmartImageViewDelegate {

    func smartImageView(_ smartImageView: SmartImageView, numberOfFacesFound: Int) {
        print("Found: \(numberOfFacesFound) face(s)")
    }

    func smartImageView(_ smartImageView: SmartImageView, viewForFaceIn frame: CGRect) -> UIView {
        let customView = UIView(frame: frame)
        customView.backgroundColor = .yellow
        customView.alpha = 0.5
        return customView
    }

    func smartImageView(_ smartImageView: SmartImageView, encountered error: Error) {
        print(error.localizedDescription)
    }

}

作者

manuelbulos, [email protected]

许可

SmartImageView 可在 MIT 许可下使用。更多信息请参阅 LICENSE 文件。