0

我想使用 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];
        }
    }
}
}

谢谢....

4

1 回答 1

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];
}
于 2014-08-07T16:11:18.340 回答