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 8254695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:16:51+00:00 2026-06-08T01:16:51+00:00

I faced a strange problem, the scrollview does not scroll down, only scroll up.

  • 0

I faced a strange problem, the scrollview does not scroll down, only scroll up. I have scrollview in my app, please look at my coding

.....

self.scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, 320,427)];

[self.view addSubViews: self.scrollView];

UIView *blueView = [[UIView alloc] initWithFrame: CGRectMake(0, 47, 320, 320)];

blueView.backgroundColor = [UIColor blueColor];

[self.scrollView addSubViews: blueView];

self.scrollView.contentSize = CGSize(320, 640);

....

My problem is no matter what value I changed contentSize, my ScrollView only scroll up, not scroll down. I want user can move blueView to the top or bottom of iPhone screen from the original position.

do you have this problem?

  • 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-08T01:16:54+00:00Added an answer on June 8, 2026 at 1:16 am

    The Problem

    It looks like your issue is with how you’re orienting blueView within scrollView. You’re setting the frame of blueView to the CGRect (0, 47, 320, 320). When you set the frame like this, one of the things you’re implicitly saying is:

    The top edge of blueView is 47 points below the top edge of scrollView.

    That’s a perfectly valid thing to say, but it’s what’s causing the problem you describe. scrollView won’t scroll down because it is designed to start, by default, with the rect (0, 0, 320, 480) in view. The contentSize property only indicates the size of the content within the UIScrollView, not its positioning. When you set it, you’re basically telling scrollView:

    Starting from your content origin, the content is 320 points wide and 640 points tall.

    Thus, scrollView won’t scroll up because, as far as it knows, there’s no content above the coordinate (0, 0).


    The Solution

    There are three steps you’ll need to take to get the functionality you want.

    1. Set the contentSize to be just big enough to allow blueView to scroll all the way up and down.
    2. Put blueView in the vertical center of scrollView.
    3. Scroll the scrollView so that it is initially centered on blueView.
    • Set the contentSize to be just big enough to allow blueView to scroll all the way up and down.

    We’ll want to calculate the correct value of the contentSize property. It is of the type CGSize, so we need two parts: width and height. width is easy – since you don’t seem to want horizontal scrolling, just make it the width of the screen, 320. Height is a little more tricky. If you want blueView to just touch the top and bottom of the screen when scrolled up or down, you need to do some math. The correct total height will be double the height of the screen, minus the height of blueView. So:

    scrollView.contentSize = CGSizeMake(320, 480 * 2.0 - blueView.frame.size.height);
    
    • Put blueView in the vertical center of scrollView.

    That’s easy; just set the center property of blueView:

    blueView.center = CGPointMake(160, scrollView.contentSize.height / 2.0);
    
    • Scroll the scrollView so that it is initially centered on blueView.

    If you check the Apple UIScrollView documentation, you’ll see an instance method - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated. This is exactly what you need to scroll scrollView programmatically. The rect you want is the one centered on blueView, with the size of the iPhone screen. So:

    CGRect targetRect = CGRectMake(0, scrollView.contentSize.height / 2.0 - 240,
                                   320, 480);
    [scrollView scrollRectToVisible:targetRect animated:NO];
    

    Make sure you do this scrolling in viewWillAppear, so it’s ready right when the user sees the view.

    That should be it. Let me know if you have any questions!

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

Sidebar

Related Questions

We've faced strange problem. We have log on service, that authenticates user, adds auth
Today I faced a strange problem in C#. I have an ASP.NET page where
Today I faced a strange problem. I have an application which is the same
I've faced with a strange problem in ASP.net/SQL Server and really can not find
I faced this strange situation where foreach like construct of javascript does not work
I am using Cocos2d engine and I've faced a strange problem. I have a
i just faced a very strange problem today. My Application Structure is: /app -
I've faced a bit strange problem. There is a site client would like to
I faced SSLHandshakeException on Heroku. This app was not SSL app. But this app
I have a graffiti blog and i have a strange problem which is showing

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.