MaskingLayer




TAG:  Masking Layer , Mask  ,  Image  , Mask Image , Layer , Swift 

Licence:  MIT

Classification:  Masking Layer

Platform:  IOS

Language:  Swift

Device:
iPhone

Download

Installation

Podfile:
pod 'MaskingLayer'

Example

To run the example project, clone the repo, and run pod install from the Example directory first. You can select background color, camera roll, video roll with long tap.

Example ViewController
import UIKit
import MaskingLayer

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let mO = MaskingLayerViewModel(minSegment: 15)
        let MV = MaskGestureViewModel(mO: mO, vc: self)
        MV.maskGestureView?.frame = view.frame
        view.addSubview(MV.maskGestureView ?? UIView())

        mO.frameResize(images: UIImage(named: "IMG_4011")!)
    }
}

Example Code

import UIKit
import MaskingLayer

class CameraViewController: UIViewController {

    static func identifier() -> String { return String(describing: ViewController.self) }

    static func viewController() -> ViewController {

        let sb = UIStoryboard(name: "Camera", bundle: nil)
        let vc = sb.instantiateInitialViewController() as! ViewController
        return vc
    }

    private var mVM              : MaskingLayerViewModel? = nil
    private var mBObject         : MaskButtonView? = nil
    private var d: UIView?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        d = UIView(frame: CGRect(x: 0, y: 44, width: self.view.frame.width, height: self.view.frame.height - 188))
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(true)

        mBObject?.cameraMatte.isHidden = false
        mBObject?.cameraRecord.isHidden = false
        
        mVM = MaskingLayerViewModel(vc: self)
        mBObject = MaskButtonView(frame: self.tabBarController?.tabBar.frame ?? CGRect())

        self.tabBarController?.tabBar.addSubview(mBObject?.cameraMatte ?? UIButton())
        self.tabBarController?.tabBar.addSubview(mBObject?.cameraRecord ?? UIButton())

        mBObject?.cameraMatte.addTarget(self, action: #selector(btAction), for: .touchUpInside)
        mBObject?.cameraRecord.addTarget(self, action: #selector(cameraAction), for: .touchUpInside)

        view.addSubview(d ?? UIView())
        mVM?.cmareraPreView(d ?? UIView())

    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(true)

        mBObject?.cameraMatte.isHidden = true
        mBObject?.cameraRecord.isHidden = true
        d?.removeFromSuperview()
        mVM?.cameraReset()
        mVM = nil
    }

    // DyeHair Set
    @objc func btAction() { mVM?.btAction() }

    // Save photosAlbum
    @objc func cameraAction() { mVM?.cameraAction() }

}

0 Comments: