iOS:通过点击和拖动在iPad应用程序内的图像上动态引入UILabel或UITextView



我需要在图像上进行注释。

可能是一个我目前看不到的简单解决方案。

我需要通过TouchesBegan/TouchesMoved/TouchesEnded方法(这是我尝试过的)将UILabel或UITextView引入到当前显示在iPad上的图像中,然后在创建的UILabel或UITextView中添加一些文本。因此,我需要将添加的文本嵌入到特定的图像中。

有什么想法吗?

因此,您将创建一个自定义标签,移动它,当用户移动完它时,您将使用:

CGSize size = image.size;
UIGraphicsBeginImageContextWithOptions( size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// UIImages and CGImageRefs are flipped
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, size.height);
CGContextConcatCTM(context, flipVertical);
CGContextDrawImage(context, rect, [image CGImage]); // draw the image
// CGContextConcatCTM(context, flipVertical); uncomment if the text is flipped - not sure now
[label.text drawAtPoint:label.frame.origin withFont:label.font];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;

最新更新