现在的位置: 首页 > 综合 > 正文

IOS-DEMO3 scrapeAward/刮奖/脱衣服 -简单

2018年05月26日 ⁄ 综合 ⁄ 共 2051字 ⁄ 字号 评论关闭


描述:ios曾经很火的脱衣服美女app 刮奖app的实现远离 是两张图片 第一张随着手指的滑动 清除部分像素然后再重新放上去。
效果图:


过程描述:
1.通过touchMove获得移动位置。
2.用UIGraphicsBeginImageContext重新载入图片
3.然后将图片绘制入imageContext
4.并通过CGContextClearRect清除不要的像素
5.图片重新设置给imageView.
6.关闭UIGraphicsEndImageContext();

代码:
//
//  PLLViewController.m
//  DemoScrapeAwrad
//
//  Created by liu poolo on 14-7-31.
//  Copyright (c) 2014年 liu poolo. All rights reserved.
//

#import "PLLViewController.h"

@interface PLLViewController (){
    BOOL isTouchImageView;
}

@end

@implementation PLLViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.topImageView.image=[UIImage imageNamed:@"2A.jpg"];
    self.bottomImageView.image=[UIImage imageNamed:@"2B.jpg"];
    [self.topImageView setUserInteractionEnabled:YES];
    isTouchImageView=NO;
     // Do any additional setup after loading the view, typically from a nib.
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
 
    UITouch *touch= [touches anyObject];
    if([touch view]==self.topImageView){
        isTouchImageView=YES;
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
   
    if(isTouchImageView){
        UITouch* touch=[touches anyObject];
        CGPoint point=[touch locationInView:self.topImageView];
       
        UIGraphicsBeginImageContext(self.topImageView.frame.size);
        [self.topImageView.image drawInRect:self.topImageView.frame];
        CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectMake(point.x-5, point.y-5, 10, 10));
        self.topImageView.image=UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
       
       
       
//        UIGraphicsBeginImageContext(self.topImageView.frame.size);
//        [self.topImageView.image drawInRect:self.topImageView.bounds];
//        CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectMake(point.x-5, point.y-5, 10, 10));
//        self.topImageView.image=UIGraphicsGetImageFromCurrentImageContext();
//        UIGraphicsEndImageContext();
    }
   
   
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    isTouchImageView=NO;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

抱歉!评论已关闭.