[英]iOS : Scroll view works only after keyboard appears
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.
我添加了更新的TPKeyBoardAvoidingScrollView并将其添加到滚动视图的文件所有者中。 I added the outlet in .h file, synthesized in .m file and added the line
[self.view addSubview:scrollObject];
我在.h文件中添加了插座,在.m文件中合成并添加了行
[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;
do you have : 你有没有 :
scrollViewObj.contentsize > scrollViewObj.frame.size.height ?
also how do you adding those lot of textFields into? 另外你如何将那些大量的textFields添加到? (programmatically/storyboard)?
(编程/故事板)?
I fixed this problem by adding the following at the end of viewDidLoad: 我通过在viewDidLoad的末尾添加以下内容来解决此问题:
scrollViewObj.contentInset = UIEdgeInsetsMake(0, 0, self.view.bounds.size.height * 2, 0); 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.
如果设置为0,则其他边缘插入最佳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.