在ePub阅读器中设置uipageviewcontroller

时间:2013-08-12 10:25:29

标签: iphone ios epub uipageviewcontroller

我想使用UIPageViewController来实现电子书阅读器。

我唱的演示是AePubReader

如何使用UIPsgeViewController实现真正的翻页效果。

如何在翻页时添加设置页面索引....

下一页和上一页方法:

- (void) gotoNextPage {
if(!paginating){
    if(currentPageInSpineIndex+1<pagesInCurrentSpineCount){
        [self gotoPageInCurrentSpine:++currentPageInSpineIndex];
    } else {
        [self gotoNextSpine];
    }       
}
}

- (void) gotoPrevPage {
if (!paginating) {
    if(currentPageInSpineIndex-1>=0){
        [self gotoPageInCurrentSpine:--currentPageInSpineIndex];
    } else {
        if(currentSpineIndex!=0){
            int targetPage = [[loadedEpub.spineArray objectAtIndex:(currentSpineIndex-1)] pageCount];
            [self loadSpine:--currentSpineIndex atPageIndex:targetPage-1];
        }
    }
}
}

...谢谢

1 个答案:

答案 0 :(得分:0)

只有在将html渲染为webview后才能在脊椎中找到页数。我的确如下

- (void) setPagination:(UIWebView *) webView
{
    NSString *varMySheet = @"var mySheet = document.styleSheets[0];";

    NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
    "ruleIndex = mySheet.cssRules.length;"
    "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
    "}";

    NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'height: %fpx; -webkit-column-gap: 0px; -webkit-column-width: %fpx;')", webView.frame.size.height, webView.frame.size.width];
    NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];
    //NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", currentTextSize];

    [webView stringByEvaluatingJavaScriptFromString:varMySheet];

    [webView stringByEvaluatingJavaScriptFromString:addCSSRule];

    [webView stringByEvaluatingJavaScriptFromString:insertRule1];

    [webView stringByEvaluatingJavaScriptFromString:insertRule2];


    CGSize contentSize = CGSizeMake([[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth;"] floatValue],
                                    [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue]);
    self.pageVO.chapterVO.pageCountInChapter = contentSize.width/webView.frame.size.width;

//    NSLog(@"content width : %f ,frame width : %f ,my page count : %f",contentSize.width,webView.frame.size.width,contentSize.width/webView.frame.size.width);
    CGPoint point = CGPointMake(0, 0);
    if([self checkIsPageIndexOutOfRange])
    {
        //after decreasing font size page will be left blank
        [self.pageVO setIndexOfPage:self.pageVO.chapterVO.pageCountInChapter-1];
        [_myDelegate myWebViewOnPageOutOfRange];
    }
    else
    {

        if([self.pageVO getIndexOfPage] ==PAGE_INDEX_GREATER_THAN_PAGE_COUNT)
        {
            //load last page of chapter
            [self.pageVO setIndexOfPage:self.pageVO.chapterVO.pageCountInChapter-1];
        }

        if([self.pageVO getIndexOfPage] !=GET_PAGE_INDEX_USING_WORD_ID)
        {
            point = CGPointMake([self.pageVO getIndexOfPage]*webView.frame.size.width, 0);
            self.scrollView.contentOffset = point;
        }
    }
    [_myDelegate myWebViewDidLoadFinish];
}