[英]What is the most efficient way to implement drawings in app?
I want to implement freeform drawing in my PDF reader app. 我想在我的PDF阅读器应用程序中实现自由形式绘图。 I saw a tutorial which uses UIImageView
as the view where the drawings are rendered. 我看到了一个教程,它使用UIImageView
作为渲染图形的视图。 I tried this and it works well, except when I try to save the drawing. 我试过这个并且效果很好,除非我尝试保存绘图。 Sometimes it prevents me from going from one page to another unless I tap the edges twice, other times the transition is smooth. 有时它会阻止我从一个页面移动到另一个页面,除非我轻拍两次边缘,其他时候过渡是平滑的。
So what is the best way to implement this functionality? 那么实现此功能的最佳方法是什么?
--ADDITIONAL INFO-- - 附加信息 -
To save the drawing, what I do is save it as an image using UIImagePNGRepresentation
to save it in the directory. 为了保存图形,我所做的是使用UIImagePNGRepresentation
将其保存为图像以将其保存在目录中。 The saved image's file name is based on the bookId and page number of the document (eg 121-5.png) 保存图像的文件名基于bookId和文档的页码(例如121-5.png)
Now to load the drawing, a function is called which checks if an image is present based on the book's id and page number. 现在要加载绘图,将调用一个函数,该函数根据图书的ID和页码检查图像是否存在。 So if the book has and ID of 121 and I am on page 5, the function will then load the image "121-5.png". 因此,如果书的ID为121且我在第5页,则该函数将加载图像“121-5.png”。
This is just a guess (and its too late where I am to expand much on it), but if you're trying to do the saving part in the most obvious way, probably you're stalling the main (UI) thread. 这只是一个猜测(而且我要在其上进行扩展太晚了),但是如果你试图以最明显的方式进行保存部分,可能你会停止主(UI)线程。 Its possible you're not, so sorry if its presumptuous. 它可能你不是,如果它是冒昧的,那就很抱歉。 If so, this will cause the whole interface to stall out until the image has been rendered, compressed, and saved. 如果是这样,这将导致整个界面停止运行,直到图像被渲染,压缩和保存。
Two easy-ish methods to fix that: 两种简单方法来解决这个问题:
NSOperation
is a start. Here's a random tutorial ) (搜索NSOperation
是一个开始。这是一个随机教程 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.