2012-07-11 36 views
0

我有一本雜誌應用程序,其中包含大圖像。當我想翻頁時,翻頁前會有很長的延遲。所以我嘗試緩存之前,當前和下一頁,但沒有效果。我想我添加viewControllers但這些只是獲取圖像文件沒有繪圖。有沒有辦法在翻頁之前如何在背景中繪製圖像?有一些代碼:UIPageView - 捲曲很慢

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」 只是讓位置和圖像的矩形,並做 「[自我addSubView:圖片]」。 (個體經營=視圖頁)

的圖像畫面:

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

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

我知道的一個方法是如何做的,但我認爲這是不好的方法。只需隱藏上一個和下一個視圖,以及當我開始將設置視圖變爲可見時。那麼有沒有其他的方式來加載圖像並加速轉向? Thx回覆。

回答

0

我有解決方案...加載prev和下一個視圖,將它們添加到父視圖,並使用sendSubviewToBack方法發回它們。真棒!