I am creating an epub reader on IOS platform. Basically, it uses UIWebview to display epub files, I read the code of open source Aepubreader and find it's very good but not text based. I want to make it text based and page turn like iBooks.
So I try to refine the Aepubreader
The basic logic flow is
unzip the epub file.
parse the meta data(opf,toc file).
load html files by UIWebView and bind it to UIPageViewController
Everything works good except the performance.
Supposing the epub has ten html files(file1 - file10). file1 ~ file9 is small size(like 100k), but file 10 is 1MB.
when I read to the first page of file10, it costs a lot time to load this 1MB file. That's acceptable since it's the first time.
But when I turn to the second page of file10. I still need to load this 1MB file again and call a js to scroll offsetx by page number.(no way to copy a UIWebView per Apple Offical Document). This is not acceptable. I can't let user always wait when turn page on this file.
Finally I got a solution to avoid reloading this big file.
When I get first page of file10 displayed. I capture this visible view as an image, but not display it, when I turn to next page, I display this image for the page1, in the meanwhile , I give the UIwebview to from page1 to page2. like Page2.view.addSubview(webviewfrompage1). this will avoid reload webview and save time.
But, another problem is coming, Page2.view.addSubview(webviewfrompage1) will cause page2 layoutsubview, which means page2 will redraw its view to show the webview content. This is a 1MB file content, redraw still cost time, and it'll stuck the page turn animation.
I searched a lot but still have no solution.
I check the iBooks, it works perfect. How did it hanle the big file?
Please let me know if you have any thoughts on this. or other solution to handle epub display.
Thanks in advance
---------------------------------------------------------------------------------------------
reply to torazaburo:
Yes, you are absolutely right. I planned to use window.scroll(offsetX, offsetY) to get next page content.
But that's not enough. I want the page turn animation just like ibooks. So I use UIPageViewController. Using UIPageViewController means I have to implement following two delegates
-(UIViewController *)pageViewController: (UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
}
(UIViewController *)pageViewController: (UIPageViewController *)pageViewController viewControllerBeforeViewController: (UIViewController *)viewController{
}
In each deleagte, I need to alloc a viewcontroller, reload the url and set offset to location proper page. So Every time page turn, it's not just
set offset for content but alloc a new uiwebview and reload url then set offset.
torazaburo, what do you think?