美文网首页程序员iOS Developer
IOS:OC--小案例(刮刮乐的实现)

IOS:OC--小案例(刮刮乐的实现)

作者: 任任任任师艳 | 来源:发表于2017-06-13 17:09 被阅读0次

ViewController.m

import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)UIImageView * imageV;
@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
    label.text = @"因为你是彭于晏呀";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont fontWithName:nil size:50];

    [self.view addSubview:label];

    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(100, 50, 200, 250)];
    self.imageV.image = [UIImage imageNamed:@"a.jpg"];
    [self.view addSubview:_imageV];
    //

}
//触摸且移动
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

//获取图片的任意一点
UITouch * touch = touches.anyObject;

CGPoint contentPoint = [touch locationInView:self.imageV];
CGRect rect = CGRectMake(contentPoint.x, contentPoint.y, 10, 10);
//开启图片上下文
UIGraphicsBeginImageContextWithOptions(self.imageV.bounds.size, NO, 0);
// 获取花瓣上下文
CGContextRef ref = UIGraphicsGetCurrentContext();
//嫁给你imgeV的layer层映射到上下文中
[self.imageV.layer renderInContext:ref];
//清除划过的区域
CGContextClearRect(ref, rect);
//获取图片
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
//结束画板,图片消失
UIGraphicsEndPDFContext();
self.imageV.image = image;

}

相关文章

  • IOS:OC--小案例(刮刮乐的实现)

    ViewController.m import "ViewController.h" @interface Vie...

  • iOS刮刮乐实现

    前言 突然看到支付宝的刮刮卡功能,闲来无事,写了一个小demo。 步骤及思路 UI布局; 获取触摸位置在图片上的坐...

  • iOS “刮刮乐”的简单实现

    这两天闲来无事,做一个“刮刮乐”的小功能给大家乐一乐。哈哈哈,先来看看效果图: 这个女朋友奖很简单就可以实现:1....

  • iOS中刮刮乐功能的实现

    目前很多项目中都会用到“刮刮乐”这个功能点,处于此整理出了一套比较easy的实现方法。 在这里我主要用到了Imag...

  • iOS开发 刮刮乐效果的实现

    引言 我们平时在使用支付宝的时候, 会看到类似彩票刮刮乐的效果。如何实现的呢?下面就直接上代码了... 刮刮乐效果...

  • 刮刮乐

  • 刮刮乐

    2007年3月3日,特别的日子。 为啥特别? 第一次坐飞机,青岛飞西安,提前4个小时就到机场了,在网上研究过攻略,...

  • 刮刮乐

    2014年11月3日 刮刮乐 今天杏子又在济南火车站候车了,这次她是故地重游,明显轻松了许多。 ...

  • 刮刮乐

    设置刮开后,显示的文字Label UILabel *label = [[UILabel alloc]initWit...

  • 刮刮乐

    刮刮乐这个东西真的是越刮越快乐,尤其是他给我准备的30张,现在有些喜欢30这个数字了,哈哈哈哈哈! 他给我准备...

网友评论

    本文标题:IOS:OC--小案例(刮刮乐的实现)

    本文链接:https://www.haomeiwen.com/subject/ehtjqxtx.html