I've got an magazine app which contains big images. When I want to turn over the page there is a big delay before the page will be turned. So I try to cache previous, current and next page but without effect. I think I'm adding viewControllers but those are only getting images files without drawing. Is there any way how to draw images in background before page's turned? There's some code:
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];
}
}
Method "buildFrame" just making position and rect of images and doing "[self addSubView:image]". (self = view of page)
Image drawing:
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
if (_image != nil) [_image drawInRect:rect];
}
I know about one method how to do but I think It's bad method. Just making previous and next view hidden and when I start to turning set view visible. So is there any other way how to load images and speed up turning? Thx for reply.
I've got solution... load prev and next view, add them to parent view and send them back with method sendSubviewToBack. Awesome!