我有一个包含大图像的杂志应用程序。当我想翻页时,在翻页之前会有很大的延迟。所以我尝试缓存上一页、当前页和下一页但没有效果。我想我正在添加 viewControllers 但那些只是获取图像文件而不绘图。有什么方法可以在翻页之前在背景中绘制图像?有一些代码:
杂志视图控制器:
- (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];
}
我知道一种方法该怎么做,但我认为这是不好的方法。只是隐藏上一个和下一个视图,当我开始将设置视图变为可见时。那么有没有其他方法可以加载图像并加快转弯速度呢?谢谢回复。