UIPageView - 卷曲很慢

时间:2012-07-11 18:18:53

标签: ios ios5 uiview uiimage page-curl

我有一个包含大图片的杂志应用程序。当我想翻页时,在页面翻转之前有一个很大的延迟。所以我尝试缓存前一页,当前页面和下一页但没有效果。我想我正在添加viewControllers,但那些只是在没有绘图的情况下获取图像文件。在页面翻转之前,有没有办法在背景中绘制图像?有一些代码:

MagazineViewController:

- (void)loadViews {
NSInteger pagesCount = [_pages count];

if (currentPage == 0) currentPage = 1;
if ([[NSThread currentThread] isCancelled]) return;

if (_curPage == nil) {
    _curPage = [[PageViewController alloc] init];
    PageView *pageView = [[PageView alloc] initWithFrame:self.view.bounds];

    [pageView setPages:_pages];
    [pageView setPage:currentPage];
    [pageView setMagazineID:_magazineID];
    [pageView buildFrames];
    //[pageView setHidden:YES];

    [_curPage setView:pageView];
    //[_flipper addSubview:magazineView];

    [pageView release];
    [[NSNotificationCenter defaultCenter] postNotificationName:kPageLoadedNotification object:nil];
}

if (_prevPage == nil) {
    if (currentPage > 1) {
        _prevPage = [[PageViewController alloc] init];
        PageView *pageView = [[PageView alloc] initWithFrame:self.view.bounds];

        [pageView setPages:_pages];
        [pageView setPage:currentPage - 1];
        [pageView setMagazineID:_magazineID];
        [pageView buildFrames];

        [_prevPage setView:pageView];
        //[_pageViewController.view addSubview:_prevPage.view];

        [pageView release];
        [[NSNotificationCenter defaultCenter] postNotificationName:kPageLoadedNotification object:nil];
    }
}

if (_nextPage == nil) {
    if (currentPage + 1 <= pagesCount) {
        _nextPage = [[PageViewController alloc] init];
        PageView *pageView = [[PageView alloc] initWithFrame:self.view.bounds];

        [pageView setPages:_pages];
        [pageView setPage:currentPage + 1];
        [pageView setMagazineID:_magazineID];
        [pageView buildFrames];

        [_nextPage setView:pageView];
        //[_pageViewController.view addSubview:_nextPage.view];

        [pageView release];
        [[NSNotificationCenter defaultCenter] postNotificationName:kPageLoadedNotification object:nil];
    }
}

方法“buildFrame”只是制作图像的位置和矩形并执行“[self addSubView:image]”。 (自我=页面视图)

图像绘制:

- (void)drawRect:(CGRect)rect {
   [super drawRect:rect];

   if (_image != nil) [_image drawInRect:rect];
}

我知道一种方法怎么做,但我认为这是不好的方法。只是隐藏上一个和下一个视图,当我开始设置视图可见时。那么有没有其他方法如何加载图像和加快转动?感谢回复。

1 个答案:

答案 0 :(得分:0)

我有解决方案...加载prev和下一个视图,将它们添加到父视图并使用方法sendSubviewToBack将它们发回。真棒!