As others have noted, this would be a little easier if you hadn't used the UITableViewController , but it's not that difficult.
UITableView is a subclass of UIScrollView , so the table view delegate (your instance of UITableViewController in this case) will also receive calls to UIScrollViewDelegate methods. All you have to do is implement a method that is called every time the scroll shift changes and the frame of your "fixed" view is set.
Something like that:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGRect fixedFrame = self.fixedView.frame; fixedFrame.origin.y = 20 + scrollView.contentOffset.y; self.fixedView.frame = fixedFrame; }
Replace 20 with how many points you want them to be on top of the table. You still add self.fixedView as a sublayer of self.view , it will just make sure that it looks like a fixed position above the table view.
Edit: with the code you submitted, I assume your example 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; }
source share