简体   繁体   English

iOS:滚动视图仅在键盘出现后才有效

[英]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.

相关问题 滚动视图内的文本字段仅在键盘出现IOS之后向上移动 - Textfield inside a scroll view only moves up after keyboard appears IOS 当键盘出现时视图仅大于屏幕时,如何在iOS中滚动? - How do I scroll in iOS when view is only bigger than screen when keyboard appears? 当键盘首次出现在视图上时,uitableview将不会滚动。 后来它正常工作 - uitableview will not scroll when keyboard appears on the first launch of view. Later it works properly 键盘打开后视图更改后出现带有白色文本的ios黑色键盘 - ios black keyboard with white text appears after view change when keyboard open 键盘出现时调整视图大小(iOS) - Resize a view when a keyboard appears (iOS) 当键盘显示UITextView而不是同一视图上的UITextField时,滚动视图 - Scroll view when keyboard appears for UITextView, but not for the UITextField that's on the same view 在iOS 9仅限快捷栏模式下,与键盘顶部对齐的视图显示在错误的位置 - View aligned to top of keyboard appears in wrong place in iOS 9 Shortcut Bar only mode iOS 7 iPad方向问题,当键盘出现在UITextField上时视图向上移动时 - iOS 7 iPad Orientation issue, when view moves upside after keyboard appears on UITextField 当键盘出现iOS时向上滚动tableview行 - Scroll tableview row up when keyboard appears iOS 如何在键盘出现时使视图控制器滚动到文本字段 - How to make the view controller scroll to text field when keyboard appears
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM