iOS:滚动视图仅在键盘出现后才起作用 [英] iOS : Scroll view works only after keyboard appears

查看:21
本文介绍了iOS:滚动视图仅在键盘出现后才起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了包含大量文本字段的滚动视图.我添加了更新的 TPKeyBoardAvoidingScrollView 并将其添加到滚动视图的文件所有者中.我在 .h 文件中添加了插座,在 .m 文件中合成并添加了行 [self.view addSubview:scrollObject];

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.

有什么解决办法吗?

添加这些行并没有解决我的查询

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;

推荐答案

我通过在 viewDidLoad 的末尾添加以下内容解决了这个问题:

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);

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

参数的顺序是上、左、下、右.实验表明底部边缘插入必须设置为大于内容高度的值.如果设置为 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.

这篇关于iOS:滚动视图仅在键盘出现后才起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆