使用MDScratchImageView实现刮奖效果
https://github.com/moqod/iOS-Scratch-n-See
最终效果:
其实这是使用了别人的东西而已:)
源码:
//
// RootViewController.m
// Scratch
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "MDScratchImageView.h"
#import "UIImage+ImageEffects.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor]; UIImage *image = [UIImage imageNamed:@"show"]; // 背景图片
UIImageView *blurImageView = \
[[UIImageView alloc] initWithFrame:(CGRect){CGPointZero, image.size}];
blurImageView.image = image;
blurImageView.center = self.view.center;
[self.view addSubview:blurImageView]; // 被刮的图片
MDScratchImageView *scratchImageView = \
[[MDScratchImageView alloc] initWithFrame:(CGRect){CGPointZero, image.size}];
[scratchImageView setImage:image
radius:.f];
scratchImageView.center = self.view.center;
[self.view addSubview:scratchImageView];
} @end