2

When running my app theres a gap on the top which appears to be because the scrollview isn't scrolled completely at the top (right under the navigation bar). I've tried a few things such as

  • setContentOffset(CGPoint(x:view.frame.size.width, y:0),animated: true)
  • scrollRectToVisible(view.frame, animated: true)
  • contentInset = UIEdgeInsetsMake(0, 0, 0, 0)
  • contentOffset = CGPoint(x: 0, y: 0)
  • automaticallyAdjustsScrollViewInsets = false

however none of these have worked for me.

My views are set up such that I have my root view, which has a scrollview inside it and inside the scrollview there is another view. In the innermost view I have simply setup a few labels and text fields to play around with.

Any help would be appreciated.

The green part is the scrollview and the red is the view inside it, I simply put it like that as a reference point to see what's going on

Layout screenshot

Dimitre Bogdanov
  • 395
  • 1
  • 5
  • 18

2 Answers2

0

UPDATE FOR iOS 7

[self.scrollView setContentOffset: CGPointMake(0, -self.scrollView.contentInset.top) animated:YES];

0

your ScrollView should add a ContentView like this:

enter image description here

select your scrollView and in size Inspector bottom, set the width like this:

my inspector setting

for more details on how to handle scrollView in Interface Builder your can check out this AppleDoc Working with Scroll Views

Tom
  • 118
  • 2
  • 8
  • Unfortunately that didn't work, it somewhat centered the scrollview vertically and now the gap on the top is coming from the root view, see screenshot ont this link: (the blue is the root view) http://imgur.com/HSmGZD2 – Dimitre Bogdanov Jan 14 '16 at 01:14
  • Can you edit post show more implement code? have you use `Storyboard`? – Tom Jan 14 '16 at 01:26
  • I really don't have any code implementation, the only code I have set is to set the colours of the different views for references and setting the first text field to be first responder in the viewDidLoad() and yes I am using storyboard. – Dimitre Bogdanov Jan 14 '16 at 01:28
  • My hierarchy of views looks like this: http://imgur.com/LaLP8NS the way I've done it is I added all my labels and textviews that I wanted to test with and then I embedded them in a View and then I embedded that view in a Scrollview – Dimitre Bogdanov Jan 14 '16 at 13:58
  • Good job, so i think my answer is helpful. – Tom Jan 14 '16 at 16:22