UIScrollView -setContentInset not working

I have a fairly simple scroll setting, and I want to get rid of the content.

Myviewcontroller.h

@interface MyViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end

MyViewController.m

@interface MyViewController

-(void)viewDidLoad
{
    [super viewDidLoad];

    [self.scrollView setContentInset:UIEdgeInsetsZero];
    ...
}

In my storyboard, my scrollview starts at the bottom of the navigation bar. Unfortunately, I get the following result when starting the application. It appears that ContentInset is still very lively. I made a green scrollView background.

app

EDIT: by simply providing a storyboard drawing and an output link

storyboard

0
source share
2 answers

So the code

[self.myScrollViewOutlet setContentInset:UIEdgeInsetsZero];

only worked when placed in -(void)viewWillLayoutSubviews.

He did not work in -(void)viewDidLoad, -(void)viewWillAppear:(BOOL)animatedor -(void)viewDidAppear:(BOOL)animated.

, !

+2

Swift 3

UIViewController, WebView, , , webView.

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews();

    webView.scrollView.contentInset = UIEdgeInsets.zero;
}
0

Source: https://habr.com/ru/post/1584799/


All Articles