ZSYMaskView 0.0.5

ZSYMaskView 0.0.5

zhusongyu维护。



ZSYMaskView

Build Status Version License Platform

一个高度自定义的遮罩引导页。

示例

静态页面

Demo~

静态页面的使用方法,传入View即可

import UIKit

class ZSYStaticViewController: UIViewController {
    @IBOutlet weak var greenView: UIView!
    @IBOutlet weak var blueView: UIView!
    @IBOutlet weak var orangeView: UIView!
    @IBOutlet weak var purpleView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let vc = MaskForStaticViewController()
        vc.maskView = [0: [greenView, orangeView], 1: [purpleView]]
        present(vc, animated: true, completion: nil)
    }
}

UIScrollView

Demo~

如何使用UIScrollView,传入View的同时,也需要传入UIScrollView。这样,即使需要遮罩的View在屏幕外,也不必担心,因为库已经帮你处理了。

import UIKit
import ZSYMaskView

class ZSYScrollViewController: UIViewController {

    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var greenView: UIView!
    @IBOutlet weak var yellowView: UIView!
    @IBOutlet weak var blueView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let vc = ZSYMaskViewController()
        vc.maskView = [0: [greenView], 1: [blueView], 2: [yellowView]]
        vc.scrollView = scrollView
        present(vc, animated: true, completion: nil)
    }
}

UITableView

Demo~

如何使用UITableView,传入View的同时,还需要传入UITableView和invisibleIndexPath(不可见的IndexPath,即还未渲染出来,你还不能拿到的Cell的IndexPath),

let vc = ZSYMaskViewController()
if let cellView = tableView.cellForRow(at: IndexPath(row: 3, section: 0)) as? CustomTableViewCell {
    vc.maskView = [0: [sender], 1: [tableView.cellForRow(at: IndexPath(row: 1, section: 0))!], 2: [cellView.cellView2]]
    vc.invisibleIndexPath = [3: IndexPath(row: 7, section: 0)]
    vc.tableView = tableView
    vc.maskInsets = [3: [UIEdgeInsets(top: 0, left: 100, bottom: 0, right: 100)]]
    present(vc, animated: true, completion: nil)
}

示例

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

使用方法

Swift

自定义遮罩层VC,继承于ZSYMaskViewController,重写reloadViews(index: Int),以刷新遮罩层,并根据传入的index判断当前遮罩步骤。

import ZSYMaskView

class MaskForStaticViewController: ZSYMaskViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    /*
     自定义遮罩层VC,根据自己传入的maskFrame来约束布局,
     放心,如果传的是maskView,库会帮你转成maskFrame,所以此处用maskFrame即可
     */
    override func reloadViews(index: Int) {
        let frame = maskFrame[index]
        if index == 0 {
            frame?.enumerated().forEach({ itemIndex, item in
                if itemIndex == 0 {
                    let label = UILabel(frame: CGRect(x: item.origin.x + 20, y: item.origin.y + 210, width: 100, height: 20))
                    label.text = "绿色View"
                    label.textColor = UIColor.green
                    view.addSubview(label)
                }
                if itemIndex == 1 {
                    let label = UILabel(frame: CGRect(x: item.origin.x, y: item.origin.y + 150, width: 100, height: 20))
                    label.text = "黄色View"
                    label.textColor = UIColor.orange
                    view.addSubview(label)
                }
            })
        }
        
        if index == 1 {
            view.subviews.forEach { item in
                item.removeFromSuperview()
            }
            frame?.enumerated().forEach({ itemIndex, item in
                if itemIndex == 0 {
                    let label = UILabel(frame: CGRect(x: item.origin.x + 30, y: item.origin.y + 150, width: 100, height: 20))
                    label.text = "紫色View"
                    label.textColor = UIColor.purple
                    view.addSubview(label)
                }
            })
        }
    }
}

要求

此库需要iOS 8.0及以上版本。

安装

ZSYMaskView可通过CocoaPods获得。要安装它,只需在Podfile中添加以下行

pod 'ZSYMaskView'

作者

ZSY,[email protected]

许可

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