Coder Social home page Coder Social logo

fffff0001 / mcscratchimageview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jaylencoding/mcscratchimageview

0.0 1.0 0.0 3.26 MB

A custom ImageView that is used to cover the surface of other view like a scratch card, user can swipe the mulch to see the view below.

License: MIT License

Swift 82.85% Ruby 17.15%

mcscratchimageview's Introduction

MCScratchImageView

MCScratchImageView

platform Swift license


GIF Showcase

Showcase1

Showcase2


Requirments

iOS 8.0+ Xcode 7.2+ Swift 4.0

Installation

CocoaPods

pod "MCScratchImageView"

Manually

Just drag MCScratchImageView.swift to the project tree

Usage

Import

If you use CocoaPods, first import MCScratchImageView

import MCScratchImageView

Define the class variables

var scratchImageView: MCScratchImageView!

Initialize it

// init()
scratchImageView = MCScratchImageView()
// init(frame:)
scratchImageView = MCScratchImageView(frame: yourRect)

Or use StoryBoard.

Set the mask image & radius

// use default touch point radius
scratchImageView.setMaskImage(yourUIImage)
// use custom touch point radius
scratchImageView.setMaskImage(yourUIImage, spotRadius: 100)

Implement the delegate methods:

// set the delegate
scratchImageView.delegate = ***

/* ... */

// implement the MCScratchImageViewDelegate method
extension YourController: MCScratchImageViewDelegate {
    
    func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) {
        print("Progress did changed: " + String(format: "%.2f", progress))
        if (progress >= 0.8) {
            mcScratchImageView.scratchAll()
        }
    }
    
}

API declaration

// current scratched progress
public var progress: CGFloat
// Determin the radius of the touch point
private(set) var spotRadius: CGFloat = 45.0

// set the mask image & radius
public func setMaskImage(_ image: UIImage)
public func setMaskImage(_ image: UIImage, spotRadius: CGFloat)

// scratch all mask fields
public func scratchAll()

Example Project

In "Example" folder.

Tips

  • Don't set the scratchImageView.image directlly, you need to use setMaskImage(paras) to set the mask image.
  • Don't set the touch point radius (var spotRadius: CGFloat) directlly.
  • The contentMode should use default resize mode.

Author

Minecode, [email protected]

License

MCScratchImageView is available under the MIT license. See the LICENSE file for more info.

mcscratchimageview's People

Contributors

jaylencoding avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.