读书人

ipad开发之-图片擦除成效

发布时间: 2012-06-27 14:20:08 作者: rapoo

ipad开发之---图片擦除效果
使用CoreGraphices框架实现的图片擦除效果。如下:

////  EraseImageView.m//  Eraser////  Created by scott.8an@gmail.com on 11-11-7.//  Copyright 2011 LittleWorn. All rights reserved.//#import "EraseImageView.h"@implementation EraseImageView#pragma mark life cycle- (void)dealloc {    [super dealloc];}- (id)initWithFrame:(CGRect)frame backgroundImage:(UIImage*)bgImage foregroundImage:(UIImage*)fgImage{    self = [super initWithFrame:frame];    if (self) {        // Initialization code.self.userInteractionEnabled = YES;self.image = bgImage;foregroundImageView = [[UIImageView alloc] initWithFrame:frame];foregroundImageView.userInteractionEnabled = YES;[foregroundImageView setImage:fgImage];[self addSubview:foregroundImageView];[foregroundImageView release];    }    return self;}#pragma mark override-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{UITouch *touch = [touches anyObject];if ([touch view] == foregroundImageView){canErase = YES;}}-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{UITouch *touch = [touches anyObject];if (canErase) {        CGPoint currentPoint = [touch locationInView:foregroundImageView];UIGraphicsBeginImageContext(foregroundImageView.frame.size);[foregroundImageView.image drawInRect:foregroundImageView.bounds];CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(currentPoint.x, currentPoint.y, 30, 30)); foregroundImageView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();}}-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{canErase = NO;}@end

读书人网 >移动开发

热点推荐