现在的位置: 首页 > 综合 > 正文

Leaves and UIWebView (1)

2013年11月14日 ⁄ 综合 ⁄ 共 7506字 ⁄ 字号 评论关闭

From: http://groups.google.com/group/leaves-developers/browse_thread/thread/27e4bf5ff3c53113

 

 


Messages 1 - 25 of 53 - Collapse all
  Newer >

     
Varedis  
View profile  
 More options Jul 16, 6:13 am
I am not sure if Tom checks this page anymore, or even if he has time 
to work on Leaves anymore, however if he is around or if anyone would 
like to do a little brainstorming on how we can enhance Leaves, feel 
free to join me. 

I am trying to implement a UIWebView with Leaves in order to show epub 
books. Now I don't need the scrolling as the text that falls off 
screen will be passed to the next page, so basically it is just a 
dynamic PDF. 

Now in theory I believe it would be possible to capture what is 
displayed in the UIWebView to an image with: 

UIGraphicsBeginImageContext(webview.bounds.size); 
[webview.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

and then animate this using the same code as the page flip. When the 
user is about to flip it would load up another UIWebView behind with 
the next bit of text. 

I am basically trying to hack and slash my way through the leaves code 
to implement this, and if anyone has anything to add, feel free


    Forward  

     

     
Saqib Saud  
View profile  
 More options Jul 16, 7:12 am

Wow! Im working on something else.... trying to zoom in/out pdf page ...and 
move it. 

for me time is short, Im stressing in finishing the job rather than adding 
perfection. 

On Fri, Jul 16, 2010 at 3:13 PM, Varedis <robert.scot...@btinternet.com>wrote: 

 


    Forward  

     

     
Melvin Dave Vivas  
View profile  
 More options Jul 16, 7:15 am

Hi Saqib, 

Will you be sharing the zoom implementation as well? I'm also interested in 
doing something similar. 

Melvin 

 


    Forward  

     

     
Saqib Saud  
View profile  
 More options Jul 16, 7:15 am

Okay I will, For now im running in alot of problems :( 

On Fri, Jul 16, 2010 at 4:15 PM, Melvin Dave Vivas <melvind...@gmail.com>wrote: 

 


    Forward  

     

     
Varedis  
View profile  
 More options Jul 19, 7:55 am
Ok, got the UIWebView working somewhat by using: 

- (void) renderPageAtIndex:(NSUInteger)index inContext: 
(CGContextRef)ctx { 
        UIGraphicsBeginImageContext(webView.bounds.size); 
        [webView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
        UIGraphicsEndImageContext(); 

        CGRect imageRect = CGRectMake(0, 0, image.size.width, 
image.size.height); 
        CGAffineTransform transform = aspectFit(imageRect, 
                                                                                        CGContextGetClipBoundingBox(ctx)); 
        CGContextConcatCTM(ctx, transform); 
        CGContextDrawImage(ctx, imageRect, [image CGImage]); 

 

It does show the WebView flipping over just as it would for a pdf, 
however in most cases it is throwing up an error, and because of this 
missing pages out. 

the error: 

bool _WebTryThreadLock(bool), 0x4b3d7a0: Tried to obtain the web lock 
from a thread other than the main thread or the web thread. This may 
be a result of calling to UIKit from a secondary thread. Crashing 
now... 

Apparently this is caused by trying to interact with UI elements on a 
background thread. 

Anybody with a little bit more experience know a way around this? 

On Jul 16, 12:15 pm, Saqib Saud <wisesa...@gmail.com> wrote: 

 


    Forward  

     

     
Varedis  
View profile  
 More options Jul 19, 11:55 am
For anyone that may be interested in this here is a little video: 

http://screencast.com/t/ZmM5MjI1 

This demo is basically taking an xml file, loading it up in a 
UIWebView and then rendering it to a static image. 

The first view you see in the video is the actual UIWebView that 
displays the content, this is a subview that is then hidden (this is 
obviously going to be a static page as well but there are a few coding 
issues to work around first. 

The blank page is also caused by the same issue mentioned above 

The third and fourth pages are the data from the UIWebView that has 
been rendered static by Leaves 

Just for fun: 

http://screencast.com/t/MDAyMWM1 

Loading up a webpage, as you can see same initial problem with the 
first two pages. But then the website basically becomes a book. 

On Jul 19, 12:55 pm, Varedis <robert.scot...@btinternet.com> wrote: 

 


    Forward  

     

     
Varedis  
View profile  
 More options Jul 19, 5:24 pm
Hi again, 

Not sure if anyone is even interested in this but might as well keep 
documenting it. 

I have managed to fix it so the first page is actually rendered, but 
the first and second page are both the same. 

This is because where I should be taking the image of the next page, I 
am actually taking the current page, so it is offsetting everything by 
one page. 

The PDFExample implements this in the render method: 

CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index + 1); 

I need to figure a way to implement the same thing for a UIWebView 

On Jul 19, 4:55 pm, Varedis <robert.scot...@btinternet.com> wrote: 

 


    Forward  

     

     
Melvin Dave Vivas  
View profile  
 More options Jul 19, 11:57 pm

I'm interested! If you get to implement this then you can even put all of 
your content online and still have the book effect. 

Melvin 
--- 
Follow me in Twitter! - http://twitter.com/donvito 

On Tue, Jul 20, 2010 at 5:24 AM, Varedis <robert.scot...@btinternet.com>wrote: 

 


    Forward  

     

     
Carlo  
View profile  
 More options Jul 20, 3:18 am
I am VERY interested too! 
But I am a beginner, and for me Xcode and ObjC are unfamiliar... 

I'll follow your progress! 

On 19 Lug, 23:24, Varedis <robert.scot...@btinternet.com> wrote: 

 


    Forward  

     

     
Varedis  
View profile  
 More options Jul 20, 3:31 am
While the possibility is there, you would be neglecting the part of 
the market that are on Ipod touches, and anyone without a data plan. 

I am developing on an Ipod touch and I find it frustrating when I need 
to connect to the internet to use an app. Especially something that 
are supposed to be portable like books. 

In my opinion, it shouldn't matter if I am at home, or up mount 
Everest, I should still be able to use the app. 

I am using in app purchasing in my app to download the book to the 
users document folder and then it will be stored in there for use at 
any time. 

On Jul 20, 4:57 am, Melvin Dave Vivas <melvind...@gmail.com> wrote: 

 


    Forward  

     

     
Varedis  
View profile  
 More options Jul 20, 7:05 am
Ok I am making some headway now, 

New video: 

http://screencast.com/t/ZDc3NWNmMDct 

Now I have chosen to show a cover image first as this is how I am 
going to want my books to work anyway, the flash of text you see at 
the start is the webview loading up, I need to try and hide that. 

The pages are then all rendered correctly, till the end of the book. 

You may also notice on my last page I have a bit of overlapped text 
from the last page, this is caused by the UIWebView not having enough 
content to scroll down far enough, so it is scrolling down to its 
limit and then repeating some text. 

I have sorted this by using javascript to insert a spacer at the end 
and sizing it to the discrepancy. 

The new video of that: 

To do still: 

Make sure that no text can be cut in half by sitting on the edge of 
the webview frame. (the biggest problem) 

Implement overlays when the user touches the middle of the screen (I 
have done this for PDF already so that should be a quick port) 

Slider to change font size (maybe also two finger pinch and pull) 

On Jul 20, 8:31 am, Varedis <robert.scot...@btinternet.com> wrote: 

 


    Forward  

     

     
Varedis  
View profile  
 More options Jul 20, 7:06 am
Forgot to include the new vid: 

http://screencast.com/t/Yjg5NGU2N 

On Jul 20, 12:05 pm, Varedis <robert.scot...@btinternet.com> wrote: 

 


    Forward  

     

     
Carlo  
View profile  
 More options Jul 20, 9:41 am
Wow! Good work! 

Can you release the source code? 

On 20 Lug, 13:06, Varedis <robert.scot...@btinternet.com> wrote: 

 


    Forward  

     

     
Varedis  
View profile  
 More options Jul 20, 9:51 am
Once I have added the last remaining bits I will be releasing the 
source code to you guys. 

One note however, I have broken the ability to view websites as books, 
in order for me to delay the immediate firing of the renderpageatindex 
method I had to change a tiny bit of leaves code. 

This seems to have stopped websites from rendering properly but for my 
included code it seems to be working fine. 

I will not be fixing this issue, unless it causes problems related to 
my app. 

On Jul 20, 2:41 pm, Carlo <carlo.ge...@gmail.com> wrote: 

 


    Forward  

抱歉!评论已关闭.