別の画像の上に UIImage を追加したプロジェクトに取り組んでいます。ここで、滑らかなタッチを使用して、そのトップ画像の一部または全体を消去する必要があります。私は私のものと非常によく似た他の多くの質問を見てきました。しかし、それらは適切に回答されていないか、私の場合は機能しない可能性があります。
このためのサンプルコードまたはチュートリアルを提案してください。
前もって感謝します
別の画像の上に 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:
指を動かして画像を消すイベント。
-(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();
}