我正在处理图像编辑应用程序。现在我已经构建了应用程序,用户可以从他们的图书馆中选择一张照片或者使用相机拍摄照片。我还有另一个视图(一个选择器视图),用户可以从中选择其他图像。通过选择其中一个图像,应用程序将用户带回主照片。如何通过触摸将图像添加到视图?
我希望用户能够触摸屏幕上的任何位置并添加他们选择的图像。
解决此问题的最佳方法是什么?
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>
谢谢!
我在更彻底地重新阅读您的问题后更新了我的答案。 – bddicken 2012-07-17 03:59:47
谢谢!我正在处理你的新答案。它帮了大忙! – 2012-07-17 04:54:01