iOS : Scroll view works only after keyboard appear

2019-06-20 23:02发布

I made the scroll view with lots of text fields in it. I added the updated TPKeyBoardAvoidingScrollView and added it in the scroll view's file owner. I added the outlet in .h file, synthesized in .m file and added the line [self.view addSubview:scrollObject];

The issue is the view starts scrolling only after keyboard appears. It does not scroll as soon as the view is loaded.

Any solution for this?

Adding these lines did not solve my query

scrollViewObj = [[UIScrollView alloc] init];
  self.automaticallyAdjustsScrollViewInsets = NO;
    [scrollViewObj setScrollEnabled:YES];
    scrollViewObj.maximumZoomScale = 4.0;
    scrollViewObj.minimumZoomScale = 0.75;
    scrollViewObj.clipsToBounds = YES;

2条回答
家丑人穷心不美
2楼-- · 2019-06-20 23:34

I fixed this problem by adding the following at the end of viewDidLoad:

scrollViewObj.contentInset = UIEdgeInsetsMake(0, 0, self.view.bounds.size.height * 2, 0);

The order of the parameters are top, left, bottom, right. Experimenting indicates that the bottom edge inset must be set to a value more than the height of the content. The other edge insets work best if set to 0.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-06-20 23:35

do you have :

scrollViewObj.contentsize > scrollViewObj.frame.size.height ?

also how do you adding those lot of textFields into? (programmatically/storyboard)?

查看更多
登录 后发表回答