[英]How to erase image by using touch in objective-c iOS?
我正在一個項目中,我在另一個圖像上方添加了一個UIImage。 現在,我必須使用平滑的觸摸擦除頂部圖像的部分或全部。 我看到了許多其他問題,這些問題與我的非常相似。 但是他們沒有得到正確回答,或者在我的情況下可能無法正常工作。
請為我建議一些示例代碼或任何教程。
提前致謝
創建圖像視圖.....
- (void)viewDidLoad
{
eraseimg1 = [[UIImageView alloc] initWithFrame:CGRectMake(20,100, 80, 80)];
eraseimg1.image = [UIImage imageNamed:@"qute.jpg"];
[self.view addSubview:eraseimg1];
eraseimg1.userInteractionEnabled = YES;
[super viewDidLoad];
}
touchesMoved:
事件移動到fingar刪除圖像。
-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [[event allTouches] anyObject];
UIGraphicsBeginImageContext(eraseimg1.frame.size);
[eraseimg1.image drawInRect:CGRectMake(0, 0,eraseimg1.frame.size.width, eraseimg1.frame.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeClear);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 50);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor clearColor] CGColor]);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastTouch1.x, lastTouch1.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastTouch1.x, lastTouch1.y);
CGContextAddRect(UIGraphicsGetCurrentContext(),CGRectMake(0,0,80,20));
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
eraseimg1.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.