简体   繁体   English

在应用程序中实现绘图的最有效方法是什么?

[英]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: 两种简单方法来解决这个问题:

  • Launch a background thread to do this, which would free up your main thread to respond to the user. 启动后台线程来执行此操作,这将释放主线程以响应用户。 (searching for NSOperation is a start. Here's a random tutorial ) (搜索NSOperation是一个开始。这是一个随机教程
  • Pass the UILayer you want to save along to the "next page" and do the save once you transition. 将要保存的UILayer传递到“下一页”,并在转换后执行保存。 It'll still stall things up a bit, but at least the user would be thinking about what to do next and you'd have a few 100ms to do something. 它仍然会使事情停滞不前,但至少用户会考虑下一步该做什么,你需要几百毫秒才能完成任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iOS上显示CVImageBufferRef的最有效方法是什么 - What is the most efficient way to display CVImageBufferRef on iOS 使用核心数据的最有效方法是什么? - What is the most efficient way to use Core Data? 在iOS中追踪时间的最有效/最精确的方法是什么? - What's the most efficient / most precise way to track time in iOS? 打开应用程序时,从后端加载数据的最有效方法是什么? - What is the most efficient way to load data from a backend when an app opens? 在文本的应用程序日志记录中持久(不在内存中)的最有效方法/策略是什么? - What's the most efficient way / strategy for persistent (not in memory) in app logging of text? 每次将应用程序推回前台时,刷新tableView的最有效方法是什么? - What's the most efficient way to refresh a tableView every time the app is pushed back to the foreground? 在应用购买中实施智能高效的方式? - Smart and efficient way to implement in app purchases? 在iOS上缩小图像的内存效率最高的方法是什么? - What is the most memory-efficient way of downscaling images on iOS? 在iOS上将高清视频缩减为SD的最快,最有效的方法是什么? - What is the fastest and most efficient way on iOS to downscale a HD video to SD? 带有过滤器的SQL大表视图-最有效的方法是什么? - A big tableview from SQL with filter - what's the most efficient way?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM