fedefrappi/AePubReader — Issue #5: Book marks and some issue fixed
Author: WebberLai
Created: 2012-01-03 03:43:44+00:00
State: open

Hi , Thanks your reader ,Can you release book marks function ??

I use your sample to read epub in my iphone project

and I change some code for read more different epub books

1. EPub.m

In this method is use to find NCX file path , I Only use this discriminant to search NCX

- (void) parseOPF:(NSString*)opfPath{
:
:
if([[[element attributeForName:@"id"] stringValue] isEqualToString:@"ncx"]){
ncxFileName = [[element attributeForName:@"href"] stringValue];
}
:
:
}
And remark others if statement , works fine so far .

2. EPubViewController.m

The picture books need add more CSS rule

- (void)webViewDidFinishLoad:(UIWebView *)theWebView
:
:
:
NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height:auto;')", webView.frame.size.width *0.75];
:
:

[webView stringByEvaluatingJavaScriptFromString:setImageRule];

3.Add page curl

actually I use some tricky step to implement page curl effect

In EPubViewController.h add

In EPubViewController.m

- (void)viewWillAppear:(BOOL)animated
:
:
UISwipeGestureRecognizer* rightSwipeRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoNextPage)] autorelease];
[rightSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];

UISwipeGestureRecognizer* leftSwipeRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoPrevPage)] autorelease];
[leftSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
//tap to show/hide tool bar
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
tapRecognizer.delegate = self;
tapRecognizer.numberOfTapsRequired = 2;
[webView addGestureRecognizer:tapRecognizer];
[webView addGestureRecognizer:rightSwipeRecognizer];
[webView addGestureRecognizer:leftSwipeRecognizer];
:
:
And change these method

- (void) gotoNextSpine {
if(!paginating){
if(currentSpineIndex+1<[loadedEpub.spineArray count]){
[self loadSpine:++currentSpineIndex atPageIndex:0];
CATransition *transition = [CATransition animation];
[transition setDelegate:self];
[transition setDuration:0.5f];
[transition setType:@"pageCurl"];
[transition setSubtype:@"fromRight"];
[self.webView.layer addAnimation:transition forKey:@"CurlAnim"];
}
}
}
- (void) gotoNextPage {
if(!paginating){
if(currentPageInSpineIndex+1=0){
[self gotoPageInCurrentSpine:--currentPageInSpineIndex];
CATransition *transition = [CATransition animation];
[transition setDelegate:self];
[transition setDuration:0.5f];
[transition setType:@"pageUnCurl"];
[transition setSubtype:@"fromRight"];
[self.webView.layer addAnimation:transition forKey:@"UnCurlAnim"];
} else {
if(currentSpineIndex!=0){
CATransition *transition = [CATransition animation];
[transition setDelegate:self];
[transition setDuration:0.5f];
[transition setType:@"pageUnCurl"];
[transition setSubtype:@"fromRight"];
[self.webView.layer addAnimation:transition forKey:@"UnCurlAnim"];
int targetPage = [[loadedEpub.spineArray objectAtIndex:(currentSpineIndex-1)] pageCount];
[self loadSpine:--currentSpineIndex atPageIndex:targetPage-1];
}
}
}
}

Now it will have a page curl effect when you swipe your finger on screen.