Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8558751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:52:59+00:00 2026-06-11T15:52:59+00:00

I’m working on a simple PDF reader, on the bottom I have a UIScrollView

  • 0

I’m working on a simple PDF reader, on the bottom I have a UIScrollView with all the pages, in the middle I have a label which should show the page numbers while you’re scrolling thru.

But I can’t figure out how to calculate the exact position and see what page is in the middle.
I also have 2 types of PDFs, once is a double paged PDF and the other one is just a single side.

This is the way I’m drawing them in the scrollview

NSInteger xPos = 20;
for(int i = 0; i < [pdf numberOfPages]; i++)
{
    ThumbViewController *tmpThumb = [[ThumbViewController alloc] initWithNibName:nil bundle:nil page:[NSString stringWithFormat:@"%i", i + 1] andPDF:pdf];

    // SINGLE SIDE PDF
    if([_issue.presentation isEqualToString:@"1"])
    {
        tmpThumb.view.frame = CGRectMake(xPos, 5, 150, 200);

        xPos += 200;
    }
    // DOUBLE SIDE PDF
    else
    {
        tmpThumb.view.frame = CGRectMake(xPos, 5, 150, 200);

        // Draw double pages
        if((i % 2) == 1)
        {
            xPos += 105;
        }
        else
        {
            xPos += 140;
        }
    }

    [_scrollView addSubview:tmpThumb.view];

    [tmpThumb release];
}

Which gives me these nice thumbnails:
enter image description here
enter image description here

But I’m stuck on the next part, when scrolling thru the UIScrollView I can’t find any good way on how to calcule which page is in the middle of the view, currently I tried this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // Calculate what page is in the middle
    NSInteger contentSize = scrollView.contentSize.width / [_readerModel.pdf numberOfPages];
    NSInteger pageNumber = floor(scrollView.contentOffset.x / contentSize);

    // Single side
    if([_issue.presentation isEqualToString:@"1"]) pageNumber = floor(scrollView.contentOffset.x / contentSize);

    NSLog(@"%d / %d", contentSize, pageNumber);

    _thumbnailPopup.titleLabel.text = [_readerModel getTitleForPage:pageNumber inIssue:_readerModel.currentIssue];
    _thumbnailPopup.pageLabel.text = [NSString stringWithFormat:@"%d", pageNumber];
}

As you can see from the picture, the pages don’t really match up (they accidentally do in the 2nd pic, but when you scroll further they don’t)
Does anyone have any experience with something like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:53:00+00:00Added an answer on June 11, 2026 at 3:53 pm

    Just to get back at this, I finally found a decent solution.

    When creating the thumbnails I saved all the positions in an array, when scrolling I just check if the position matches.

    I know this is not ideal, but calculating the position on the fly was a little hard because I have different sizes of thumbnails.

    NSInteger scrollPos = scrollView.contentOffset.x + (scrollView.frame.size.width / 2);
    
    for(NSDictionary *tmpDic in _thumbsPos) {
        NSInteger startPos = [[tmpDic objectForKey:@"start"] intValue];
        NSInteger endPos = [[tmpDic objectForKey:@"end"] intValue];
        NSInteger page = [[tmpDic objectForKey:@"page"] intValue];
    
        if(scrollPos >= startPos && scrollPos <= endPos) {
            _thumbnailPopup.titleLabel.text = [_readerModel getTitleForPage:page inIssue:_readerModel.currentIssue];
            _thumbnailPopup.pageLabel.text = [NSString stringWithFormat:@"%d", (page + 1)];
    
            return;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I have an array which has BIG numbers and small numbers in it. I
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.