私は画像編集アプリに取り組んでいます。現在、ユーザーがライブラリから写真を選択したり、カメラで写真を撮ったりできるようにアプリを作成しています。また、ユーザーが選択できる他の画像を含む別のビュー (ピッカー ビュー) もあります。画像の 1 つを選択すると、アプリはユーザーをメインの写真に戻します。
ユーザーが画面上のどこにでも触れて、選択した画像を追加できるようにしたい。
これにアプローチする最良の方法は何ですか?
touchesBegan? touchesMoved? UITapGestureRecognizer?
誰かがサンプルコードを知っているか、これにアプローチする方法の一般的なアイデアを教えてくれれば、それは素晴らしいことです!
編集:
これで、座標が表示され、UIImage がピッカーから選択した画像を取得していることがわかります。しかし、タップしても画像が画面に表示されません。誰かが私のコードのトラブルシューティングを手伝ってくれませんか:
-(void)drawRect:(CGRect)rect
{
CGRect currentRect = CGRectMake(touchPoint.x, touchPoint.y, 30.0, 30.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextFillRect(context, currentRect);
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
touchPoint = [touch locationInView:imageView];
NSLog(@"%f", touchPoint.x);
NSLog(@"%f", touchPoint.y);
if (touchPoint.x > -1 && touchPoint.y > -1)
{
stampedImage = _imagePicker.selectedImage;
//[stampedImage drawAtPoint:touchPoint];
[_stampedImageView setFrame:CGRectMake(touchPoint.x, touchPoint.y, 30.0, 30.0)];
[_stampedImageView setImage:stampedImage];
[imageView addSubview:_stampedImageView];
NSLog(@"Stamped Image = %@", stampedImage);
//[self.view setNeedsDisplay];
}
}
私の NSLogs の例については、次のように表示されます。
162.500000
236.000000
Stamped Image = <UIImage: 0xe68a7d0>
ありがとう!