iOS : Scroll view works only after keyboard appears

风格不统一 提交于 2019-12-12 10:45:59

问题


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;

回答1:


do you have :

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

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




回答2:


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.



来源:https://stackoverflow.com/questions/19709034/ios-scroll-view-works-only-after-keyboard-appears

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!