GithubHelp home page GithubHelp logo

scratchview's Introduction

ScratchView

简单封装刮奖效果

img

使用说明

###安装 #####手工导入 将项目目录下的ScratchView导入项目中 #####Pod安装

pod 'ScratchView', '~> 1.0'

###使用

  1. 导入头文件

    #import "SIScratchView.h"
  2. 添加需要遮挡的View

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(75,100, 150, 250) ];
    imageView.contentMode = UIViewContentModeScaleAspectFill ;
    imageView.image = [UIImage imageNamed:@"1"] ;
    imageView.clipsToBounds = YES ;
    [self.view addSubview:imageView] ;
  3. 设置遮罩层View

    //自定义覆盖view
    UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 250)];
    coverView.backgroundColor = [UIColor greenColor];
  4. 初始化ScratchView并添加遮罩层

    // 初始化
    - (SIScratchView *)scratchView {
     	if (_scratchView == nil) {
        	_scratchView = [[SIScratchView alloc] initWithFrame:CGRectMake(75, 100, 150, 250)];
        	_scratchView.maxPathCount = 30;
        	_scratchView.pathWidth = 50.0;
        	_scratchView.pathCount = 6 ;
        	_scratchView.scratchViewDelegate = self ;
    	}
    	return _scratchView;
    }
    
    // 添加
    [self.scratchView setCoveredView:coverView];
    [self.view addSubview:self.scratchView];

    其中属性的含义如下:

     /// 路径的宽度
     @property (nonatomic,assign) CGFloat pathWidth ;
    
     /// 行以及列的路径数,如果设置为3总共会分成3*3个块
     @property (nonatomic,assign) NSUInteger pathCount ;
    
     /// 最大路径数,经过多少块自动消失
     @property (nonatomic,assign) NSUInteger maxPathCount ;
    
     /// 被覆盖的View
     @property (nonatomic,strong) UIView *coveredView ;
    
     /// 代理
     @property (nonatomic,weak) id<SIScratchViewDelegate>scratchViewDelegate ;
    
  5. 实现代理方法

    #pragma mark --- SIScratchViewDelegate
    - (void)scratchViewDidOpen:(SIScratchView *)scratchView{
    	NSLog(@"%s",__func__) ;
    }
    

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

scratchview's People

Contributors

silence0201 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.