Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-30-2010, 10:53 AM   #1 (permalink)
Registered Member
 
TheFabolusBensun's Avatar
 
Join Date: Jan 2010
Posts: 62
TheFabolusBensun is on a distinguished road
Smile Remember the current pdf page

Trying to put 'forIndexNSInteger)index' in method title passing message of current page to make app remember stay on the same page when changing orientation (at the moment it goes back to page1):
Code:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{			NSLog(@"willAnimateRotationToInterfaceOrientation");
	UIInterfaceOrientation o = self.interfaceOrientation;
	if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown))	{D = 1;[pagingScrollView removeFromSuperview];[self setPaging];}
	if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight))	{D = 2;[pagingScrollView removeFromSuperview];[self setPaging];}}

- (void)viewDidLoad { 
	D = 1;
	[self setPaging];}

- (void)setPaging {																
	recycledPages = [[NSMutableSet alloc] init];
	visiblePages  = [[NSMutableSet alloc] init];
	CGRect F;
	F = [self frameForPagingScrollView];
	pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
	if (D == 1) {																
		pagingScrollView.pagingEnabled = YES;
		pagingScrollView.backgroundColor = [UIColor whiteColor];
		pagingScrollView.showsVerticalScrollIndicator = NO;
		pagingScrollView.showsHorizontalScrollIndicator = NO;
		pagingScrollView.contentSize = CGSizeMake(320.0f * [self pdfPageCount], 435.0f);
		pagingScrollView.delegate = self;
		pagingScrollView.clipsToBounds = YES;
		pagingScrollView.bounces = YES;
		[self.view addSubview:pagingScrollView];
		[self tilePages];
		[self.isvL removeFromSuperview];
		[pagingScrollView addSubview:self.isvP];}
	else if (D == 2) {															
		pagingScrollView.pagingEnabled = YES;
		pagingScrollView.backgroundColor = [UIColor whiteColor];
		pagingScrollView.showsVerticalScrollIndicator = NO;
		pagingScrollView.showsHorizontalScrollIndicator = NO;
		pagingScrollView.contentSize = CGSizeMake(480.0f * [self pdfPageCount], 300.0f);
		pagingScrollView.delegate = self;
		pagingScrollView.clipsToBounds = YES;
		pagingScrollView.bounces = YES;
		[self.view addSubview:pagingScrollView];
		[self tilePages];
		[self.isvP removeFromSuperview];
		[pagingScrollView addSubview:self.isvL];}}

- (CGRect)frameForPagingScrollView {
	CGRect frame;
	if (D == 1) {																
		frame = CGRectMake(0.0f, 0.0f, 320.0f, 435.0f);
		frame.size.width += (0);}
	else if (D == 2) {															
		frame = CGRectMake(0.0f, 0.0f, 480.0f, 300.0f);
		frame.size.width += (0);}
	return frame;}

- (void)tilePages {																
	if (D == 1) {																
		CGRect visibleBounds = pagingScrollView.bounds;
		int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
		int lastNeededPageIndex  = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
		firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
		lastNeededPageIndex  = MIN(lastNeededPageIndex, [self pdfPageCount] - 1); 
		for (ISVportrate *page in visiblePages) {
			if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
				[recycledPages addObject:page];
				[page removeFromSuperview];}}
		[visiblePages minusSet:recycledPages];
		for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
			if (![self isDisplayingPageForIndex:index]) {
				ISVportrate *page = [self dequeueRecycledPageP];
				if (page == nil) {
					page = [[[ISVportrate alloc] init] autorelease];}
            [self configurePageP:page forIndex:index];
            [pagingScrollView addSubview:page];
				[visiblePages addObject:page];}}}
	else if (D == 2) {															
		CGRect visibleBounds = pagingScrollView.bounds;
		int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
		int lastNeededPageIndex  = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
		firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
		lastNeededPageIndex  = MIN(lastNeededPageIndex, [self pdfPageCount] - 1); 
		for (ISVLandscape *page in visiblePages) {
			if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
				[recycledPages addObject:page];
				[page removeFromSuperview];}}
		[visiblePages minusSet:recycledPages];
		for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
			if (![self isDisplayingPageForIndex:index]) {
				ISVLandscape *page = [self dequeueRecycledPageL];
				if (page == nil) {
					page = [[[ISVLandscape alloc] init] autorelease];}
				[self configurePageL:page forIndex:index];
				[pagingScrollView addSubview:page];
				[visiblePages addObject:page];}}}}
changes (below) make it remember which page its on but only because paging scrollview not deleted, pagingScrollView frame still set at portrait with landscape setting (heigh-wise wont let vertical scroll unless zoomedin).
when I change '- (void)willAnimateRotationToInterfaceOrientation' pagingScrollView isn't deleted.
Code:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation forIndex:(NSUInteger)index{			NSLog(@"willAnimateRotationToInterfaceOrientation");
	UIInterfaceOrientation o = self.interfaceOrientation;
	if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown))	{D = 1;[pagingScrollView removeFromSuperview];[self setPaging:index];}
	if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight))	{D = 2;[pagingScrollView removeFromSuperview];[self setPaging:index];}}

- (void)viewDidLoad {
	D = 1;
	int index;[self setPaging:index];}																

- (void)setPaging:(NSUInteger)index {
	recycledPages = [[NSMutableSet alloc] init];
	visiblePages  = [[NSMutableSet alloc] init];
	CGRect F;
	F = [self frameForPagingScrollView];
	pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
	if (D == 1) {																
		pagingScrollView.pagingEnabled = YES;
		pagingScrollView.backgroundColor = [UIColor whiteColor];
		pagingScrollView.showsVerticalScrollIndicator = NO;
		pagingScrollView.showsHorizontalScrollIndicator = NO;
		pagingScrollView.contentSize = CGSizeMake(320.0f * [self pdfPageCount], 435.0f);
		pagingScrollView.delegate = self;
		pagingScrollView.clipsToBounds = YES;
		pagingScrollView.bounces = YES;
		[self.view addSubview:pagingScrollView];
		[self.isvL removeFromSuperview];
		[pagingScrollView addSubview:self.isvP];
		for (ISVportrate *page in visiblePages) {
			int index;
			if (page.index == index) {
				ISVportrate *page = [self dequeueRecycledPageP];
				if (page == nil) {
					page = [[[ISVportrate alloc] init] autorelease];}
				[self configurePageP:page forIndex:index];
				[pagingScrollView addSubview:page];
				[visiblePages addObject:page];}}}
	else if (D == 2) {															
		pagingScrollView.pagingEnabled = YES;
		pagingScrollView.backgroundColor = [UIColor whiteColor];
		pagingScrollView.showsVerticalScrollIndicator = NO;
		pagingScrollView.showsHorizontalScrollIndicator = NO;
		pagingScrollView.contentSize = CGSizeMake(480.0f * [self pdfPageCount], 300.0f);
		pagingScrollView.delegate = self;
		pagingScrollView.clipsToBounds = YES;
		pagingScrollView.bounces = YES;
		[self.view addSubview:pagingScrollView];
		for (ISVLandscape *page in visiblePages) {
			int index;
			if (page.index == index) {
				ISVLandscape *page = [self dequeueRecycledPageL];
				if (page == nil) {
					page = [[[ISVLandscape alloc] init] autorelease];}
				[self configurePageL:page forIndex:index];
				[pagingScrollView addSubview:page];
				[visiblePages addObject:page];}}
		[self.isvP removeFromSuperview];
		[pagingScrollView addSubview:self.isvL];}}

//- (CGRect)frameForPagingScrollView { same as above

//- (void)tilePages {same as above
Any ideas? Thanks
TheFabolusBensun is offline   Reply With Quote
Reply

Bookmarks

Tags
pdf

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 355
6 members and 349 guests
dre, freewind, hain, HemiMG, lendo, Newbie123
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0