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.

Overview

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.

You might also like...
CameraButton - A simple camera button that can be used for photo and video capturing
CameraButton - A simple camera button that can be used for photo and video capturing

CameraButton A simple camera button that can be used for photo and video capturi

Use Swift to pack ambiguous image that display differently on Apple and Other devices

Aibmoe Use Swift to pack ambiguous image that display differently on Apple and O

NavigationCoordinator acts as a coordinator for NavigationView in SwiftUI. You can use pushView, popView, popToView, popToRootView as you can in traditional UIKit

NavigationCoordinator NavigationCoordinator acts as a coordinator for NavigationView. You can use pushView, popView, popToView, popToRootView in Swift

Microblog-ref-app - A Twitter like social media app that users can share their moments
Microblog-ref-app - A Twitter like social media app that users can share their moments

HiPlace - iOS Table of Contents Introduction HMS Services Getting Started Suppor

An instagram-like image editor that can apply preset filters passed to it and customized editings to a binded image.
An instagram-like image editor that can apply preset filters passed to it and customized editings to a binded image.

CZImageEditor CZImageEditor is an instagram-like image editor with clean and intuitive UI. It is pure swift and can apply preset filters and customize

📸 iMessage-like, Image Picker Controller Provides custom features.

RAImagePicker Description RAImagePicker is a protocol-oriented framework that provides custom features from the built-in Image Picker Edit. Overview O

SharkCardScan is a Credit/Debit Card scanner built using Apple's Vision Framework.
SharkCardScan is a Credit/Debit Card scanner built using Apple's Vision Framework.

iOS Credit/Debit card scanner, built using Apple's Vision Framework.

Scanner for decks of cards with bar codes printed on card edges
Scanner for decks of cards with bar codes printed on card edges

The Nettle Magic Project This deck of cards has a bar code printed on the edge of each card. Scanning these bar codes would reveal where every card is

 MemojiView - MemojiView works by having a TextView behind the actual View for user input
MemojiView - MemojiView works by having a TextView behind the actual View for user input

MemojiView Since there is no official API for using the users Memoji's i have built a simple view to retrieve them and use them to your liking. Memoji

Comments
  • Not working when Background view Dynamically

    Not working when Background view Dynamically

    Hey @Minecodecraft thanks for the lib . Im new to swift , and try to run this lib through react-native.

    Problem : the scratch action doesn't work as soon as i add backgroundView ( mainImageView) .

    Here is my Example :

    class ScratchCardView: UIView {
      
      
      override init(frame: CGRect){
        super.init(frame:frame)
           
        let mainImageView = UIImageView(image:UIImage(named:"pin.jpg"))
        
        mainImageView.frame = CGRect(x:0,y:0,width:300,height:300)
    
        
        var scratchImageView: MCScratchImageView!
        scratchImageView = MCScratchImageView(frame:CGRect(x:0,y:0,width:300,height:300))
        scratchImageView.setMaskImage(UIImage(named:"pin.jpg")!, spotRadius: 10)
        
        self.addSubview(mainImageView)
        self.addSubview(scratchImageView)
        
    
      }
    
    
    }
    
    

    as soon as I comment self.addSubview(mainImageView) it works !

    opened by Kida007 1
  • Added swift_version to podspec

    Added swift_version to podspec

    This will help other library maintainers using this library as a dependency , because there is no other to specify a dependency's swift_version in your own library podspec.

    I hope this gets merged soon .

    opened by Kida007 0
Owner
Jaylen Bian
Leetcoding && fluttering
Jaylen Bian
ThreeDCardView - Library that you can see images with a 3D card 🌌

?? ThreeDCardView Usage First you have to import 'ThreeDCardView' import 'ThreeDCardView' Create ThreeDCardView and set the frame let threeDCardView:T

Fomagran 4 Jul 9, 2022
A apple music cover picture shadow style image library

ShadowImageView A apple music cover picture shadow style image library ShadowImageView is a iOS 10 Apple Music style image view, help you create elege

Old Donkey 794 Dec 17, 2022
API surface for Swift plug-ins using the Swift Plugin Manager

SwiftPlugin The minimal API surface required for the Swift Plugin Manager to create instances from a loaded plugin. Additional documentation and refer

Joakim Hassila 2 Mar 25, 2022
add text(multiple line support) to imageView, edit, rotate or resize them as you want, then render the text on image

StickerTextView is an subclass of UIImageView. You can add multiple text to it, edit, rotate, resize the text as you want with one finger, then render the text on Image.

Textcat 478 Dec 17, 2022
Rounded async imageview downloader lightly cached and written in Swift

PASImageView ============ **Rounded async imageview downloader lightly cached and written in Swift 3 ** Objective-C version here Snapshot Usage //XIB

Pierre Abi-aad 173 Nov 6, 2022
How to create a circular and rectangular ImageView with similar image?

chapter11CircularAndRectangularImage How to create a circular and rectangular ImageView with similar image? I add two imageView in Main.storyboard I a

ahmetbostanciklioglu 0 Jan 8, 2022
DG Zoomable ImageView

DGZoomableImageView A zoomable, pan-able image view Requirements iOS 12.0+ Swift

donggyu 7 Aug 17, 2022
ImageView - Component for loading and displaying different images aka SVG/PNG/JPG/JPEG

ImageView Component that loads and displays images(.svg/.png/.jpg/.jpeg) form as

Sergei 1 Mar 23, 2022
Photo Browser / Viewer inspired by Facebook's and Tweetbot's with ARC support, swipe-to-dismiss, image progress and more

IDMPhotoBrowser IDMPhotoBrowser is a new implementation based on MWPhotoBrowser. We've added both user experience and technical features inspired by F

Thiago Peres 2.7k Dec 21, 2022
FlaneurImagePicker is an iOS image picker that allows users to pick images from different sources (ex: user's library, user's camera, Instagram...). It's highly customizable.

FlaneurImagePicker is a highly customizable iOS image picker that allows users to pick images from different sources (ex: device's library, device's c

FlaneurApp 17 Feb 2, 2020