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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:15:03+00:00 2026-06-15T11:15:03+00:00

How do I fix a subviews position on screen (especially in UIScrollView and UITableView)?

  • 0

How do I fix a subviews position on screen (especially in UIScrollView and UITableView)? I think in storyboard

[self.view addSubview:aSubView];

does not work anymore.

Any ideas?

EDIT #1: I am using a UITableViewController, not a simple UITableView.

EDIT #2:

CGRect fixedFrame = self.menuViewRelative.frame;
fixedFrame.origin.y = 0 + scrollView.contentOffset.y;
self.menuViewRelative.frame = fixedFrame;

menuViewRelative = [[UIView alloc] init];
menuViewRelative.backgroundColor = [UIColor grayColor];
menuViewRelative.frame = CGRectMake(0.0, 0.0, 320.0, 50.0);

[self.view addSubview:self.menuViewRelative];
  • 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-15T11:15:05+00:00Added an answer on June 15, 2026 at 11:15 am

    As others noted, this would be a bit easier if you didn’t use a UITableViewController, but it’s not that hard anyway.

    UITableView is a subclass of UIScrollView, so table view’s delegate (your UITableViewController instance in this case) will also receive UIScrollViewDelegate method calls. All you have to do is implement the method that gets called every time scroll offset changes and adjust the frame of your “fixed” view.

    Something like this:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        CGRect fixedFrame = self.fixedView.frame;
        fixedFrame.origin.y = 20 + scrollView.contentOffset.y;
        self.fixedView.frame = fixedFrame;
    }
    

    Replace 20 by how many points you want it to be from top of the table view. You still add self.fixedView as a subliew of self.view, this will just make sure it looks like it’s in a fixed position above table view.


    Edit: with the code you posted, I’m guessing your verion should look like this:

    - (void)viewDidLoad {
        menuViewRelative = [[UIView alloc] init];
        menuViewRelative.backgroundColor = [UIColor grayColor];
        menuViewRelative.frame = CGRectMake(0.0, 0.0, 320.0, 50.0);
    
        [self.view addSubview:self.menuViewRelative];
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
        CGRect fixedFrame = self.menuViewRelative.frame;
        fixedFrame.origin.y = 0 + scrollView.contentOffset.y;
        self.menuViewRelative.frame = fixedFrame;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in -(void) viewDidLoad : for(UIView *subview in self.view.subviews) { if([subview
Help fix the encoding in the servlet, it does not display Russian characters in
In application:didFinishLaunchingWithOptions: I'm adding a split view: [self.window addSubview:splitViewController.view]; [self.window makeKeyAndVisible]; splitViewController comes from
How can I fix the following error? error: cs0016 could not write to output
I found how to fix div position using jQuery. Here is an example .
Is it possible to fix the position of a table, such that it scrolls
I have to fix a glitch with this code someone wrote but I'm not
I'm trying to fix a elements position based on the scroll position within the
I'm trying to create programatically a custom view controller with subviews which center on
I have a number of subviews on the main window. These subviews do not

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.