0

I have two table view controllers, and they both can segue to the same view which has a scroll view.

For some reason, for one view, the scroll view is lower than the other.

As you can see, the first one is coming from home view controller and is more lowered than the other one.

I have the frame's y position set as so:

_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, navBarHeight + statusHeight, self.view.bounds.size.width, self.view.bounds.size.height)];

enter image description here enter image description here

Vvk
  • 4,031
  • 29
  • 51
farhan
  • 233
  • 1
  • 13
  • doesn't clear the question.. Explain more.. – Sneha May 28 '16 at 04:18
  • I had the same issue, And i fixed it by adding one UIView before UIScrollView ... [Check Here](http://stackoverflow.com/questions/36866127/scrollview-issue-swift/36867778#36867778) – Bala May 28 '16 at 05:42

3 Answers3

1

You don't need to account for the nav bar and status bar height when setting the frame of your subview. Instead of y equal to navBarHeight + statusHeight, set y equal to 0.

If there's still a gap, also set your view controller's automaticallyAdjustsScrollViewInsets property to false to prevent that behavior:

self.automaticallyAdjustsScrollViewInsets = NO;
Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
  • i already have that. Still no result. – farhan May 28 '16 at 04:37
  • @farhan Oh, I just re-read your question. The issue is that you set y to navBarHeight + statusHeight. Set it to 0. You don't have to account for the status height or nav bar height. – Lyndsey Scott May 28 '16 at 04:38
  • yes, i have it set as navBarHeight + satusHeight because i want the scrollview to be starting right at under the navbar. the second image as you can see does that fine. – farhan May 28 '16 at 04:40
  • @farhan Is the nav bar above your views the UINavigationController navigation bar? Or did you add it to your view otherwise? – Lyndsey Scott May 28 '16 at 04:42
  • Yes, its above my views. Im just thinking at this point ill create a new viewController. Been trying this all day. – farhan May 28 '16 at 04:43
  • @farhan You misunderstood my question... Are you using a UINavigationController? Also, did you set both scrollviews using the same exact frame? And is auto layout enable? – Lyndsey Scott May 28 '16 at 04:45
  • Yes i am using a UINav Controller. The view is fully created through code. but the view controller is in storyboard which is segued from another controller and has nav bar – farhan May 28 '16 at 08:24
  • @farhan you didn't answer all of my questions so it's hard for me to diagnose the issue, but if you post your project somewhere, I can take a look at it – Lyndsey Scott May 28 '16 at 13:42
0

If you want the scrollview to be starting right at under the navbar,you can set y to 0,and

self.automaticallyAdjustsScrollViewInsets = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
Ye HB
  • 11
  • 2
0

In your storyboard, click on your view controller. In the Attributes inspector uncheck Adjust Scroll View Insets and you're done.

Uncheck Adjust Scroll View Insets

Burak
  • 525
  • 4
  • 24