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

  • SEARCH
  • Home
  • 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 8912665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:15:38+00:00 2026-06-15T04:15:38+00:00

I am using UIScrollView to show lots of subviews. Below is the code for

  • 0

I am using UIScrollView to show lots of subviews. Below is the code for creating scroll view:

ScrollView = [[UIScrollView alloc]initWithFrame:CGRectZero];
ScrollView.delegate = self;
ScrollView.showsHorizontalScrollIndicator = NO;
ScrollView.showsVerticalScrollIndicator = NO;
ScrollView.clipsToBounds = YES;
ScrollView.scrollEnabled = YES;
ScrollView.pagingEnabled = YES;

CGFloat widthOfScroll= (maxTotalColumnsVisibleAtAnyPoint * widthOfSubView );

ScrollView.frame = CGRectMake(0, 0, widthOfScroll, heightOfSubView);

CGSize contentSizeHeaderView =  self.ScrollView.frame.size;
CGFloat contentSizeWidth =  self.totalSubViews * self.widthOfSubView;
contentSizeHeaderView.width =  contentSizeWidth;

[ScrollView setContentSize:contentSizeHeaderView];

THe code for adding controls to ScrollView and event handler for scrollView are below::

-(void)loadControlsInScroll{


    UIView *tempSubView = nil;
    CGFloat tempOriginX = 0;
    @autoreleasepool {


        for (int i = 0; i < self.totalSubViews; i++) {


            tempSubView = [dataSource viewForScroll:i];
            tempSubView.layer.borderColor = borderColor.CGColor;
            tempSubView.layer.borderWidth = kBorderWidth;
            tempSubView.frame = CGRectMake(tempOriginX, 0, widthOfSubView, heightOfSubView);
            tempOriginX = tempOriginX + widthOfSubView;

            [self.ScrollView addSubview:tempSubView];
        }

    }

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
///Event handler
}

I have enabled paging in this scroll view.

Let us assume that at max scrollView can hold 8 subviews in its frame.

CASE 1:

16 subviews are added to the scrollview. Now two page are displayed. Scrolling to both pages are working correctly. Touching subviews in both pages does not cause any incorrect behavior.

CASE 2:

9 subviews are added to the scroll view. Now also it is tow paged. First pages contain 1st-8th subviews. Page two contain 2nd-9th subviews.
Now touching subviews in Page 1 works normal. Touching in Page 2 calls the event handler scrollViewDidScroll of UIScrollView.

enter image description here
enter image description here

MORE INFORMATION:

  1. This does not happen if PagingEnabled is set to NO.

Why this scrollViewDidScroll event gets called even though no scrolling was manually done? The event handler scrollViewWillBeginDragging is also called at this time?

UPDATE 1:

The real problem is that if PagingEnabled is YES, then whether delegate of scrollview is set or not, in case 2, the scroll view automatically scrolls to the previous page.

  • 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-15T04:15:40+00:00Added an answer on June 15, 2026 at 4:15 am

    The problem is that Paginenabled property of UIScrollView always scroll the scrollview to width of its bounds. So When you have 9 subviews it tries to scroll to 2nd page and shows you 2-9 subviews. In actual your page1 has subviews 1-8 and 2nd pgae has only 9 number subview. So The real problem is that UIScrollview’s content width should be proportional to your number of Pages. In your case your 1 page holds 8 subviews. so content size should be
    Width of UIScrollview * no. of Pages.

    // noOfpages = No of pages in scrollview (Each page has 8 subviews)
    // noOfSubviews
    int noOfpages = 
    if(noOfSubviews%8==0){
       noOfPages = noOfSubviews/8;
    
    }else{
       noOfPages = noOfSubviews/8 + 1;
    }
    scrollview.contentSize = CGSizeMake(scrollview.frame.size.width*noOfPages,scrollview.frame.size.height); 
    

    In this way scrolling on first page will take you to view 9. and scrolling back will take you back to subview 1-8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added a UIScrollVIew using IB. Then using the following code i add
I have a UIScrollView which I create and size dynamically using... scrollView.contentSize = CGSizeMake(scrollView.frame.size.width
So Im making a two UIscrollview in my view. I'm using Ray Wenderlich 's
I am using this code to show scrolling images but I am only getting
In my app i am using UIScrollview to list details. In scrollview the first
I have a UIView that I'm sliding in using a UIScrollView. Code looks like
I have to display images from the Photo Library using UIScrollview. Except the first
I am working on an application in which I am using UIScrollview , in
I am using a UIScrollView in an iPhone xib, and a property called myScrollView
I currently am using a UIScrollView to work as a way of scrolling/ dragging

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.