IOS7:UINavigationController 中的 UIScrollView 偏移 [英] IOS7 : UIScrollView offset in UINavigationController

查看:16
本文介绍了IOS7:UINavigationController 中的 UIScrollView 偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 ios 7 上迁移我的应用程序,但我已经在新的导航控制器/栏管理上被困了几个小时.

I'm currently migrating my app on ios 7 and I've been stuck for hours on the new navigationcontroller/bar management.

以前,当我们有一个导航控制器时,我们有一个这样的片段:

Before, when we had a navigation controller, we had a snippet like this :

UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:[[MainViewController alloc]init]];

在界面构建器中,我们可以选择为视图设置现有的导航栏,并且所有内容都与真实视图的内容相匹配.

In interface builder, we had the choice to set an existing navigationbar for the view and everything match the content of the real view.

好的,现在我不知道如何使用界面生成器正确设计.我仍然有我的代码段来初始化我的导航控制器.但是,在 MainViewController 的界面构建器中,如果我将状态栏设置为半透明或不透明导航栏,则顶部的偏移量为 44px(见下文).

OK so now, i have no clue of how to design properly with interface builder. I still have my snippet to initialize my navcontroller. However in the interface builder for my MainViewController if I set a status bar to translucent or opaque navigation bar, i have an offset of 44px at the top (see below).


Interface Builder_________________________和结果


Interface Builder_________________________And the result


现在,如果我将状态栏设置为无,则顶部没有偏移,但由于模拟器上的视图因导航栏而变小,因此界面构建器中的视图底部被切断.

Now, if i set status bar to none, there is no offset at top but since the view on simulator is smaller because of navigation bar the bottom of the view in interface builder is cut off.

Interface Builder________________________和结果

Interface Builder_________________________And the result

我想我真的在这里遗漏了一些东西,但我在 iOS7 Transitions Guide 中找不到任何关于此的主题或苹果信息.

I guess i'm really missing something here but i can't find any topic or apple info in iOS7 Transitions Guide about that.

感谢您的帮助


编辑

如图所示,view的第一个child是一个包含两个labels的UIScrollView,没有scrollview时不会出现这个问题.如果它是 UITableView,它也会出现.如果标签在 UIScrollView 之外,则该标签没有偏移.

As we can see in the pictures, the first child of the view is a UIScrollView which contains both labels, the problem does not appear when there is no scrollview. It also appears if it's a UITableView. If a label is outside the UIScrollView, there is no offset to that label.

推荐答案

好的,所以我找到了解决方案,我在我的控制器中设置了属性:

OK so i found the solution, I have set in my controller the property:

self.automaticallyAdjustsScrollViewInsets = false

虽然我不太明白这个属性的真正好处,(或者为什么默认值为 true)

I don't really understand the true benefit of this property though, (or why the default value is true)

我在那里找到的唯一文档:

The only documentation i found was there:

更新

在 iOS 11 中 automaticallyAdjustsScrollViewInsets 已弃用

In iOS 11 automaticallyAdjustsScrollViewInsets is deprecated

您现在应该使用:

self.tableView.contentInsetAdjustmentBehavior = .never

我还鼓励您查看这个问题及其答案以获得更好的答案了解这些属性

I also encourage you to check this question and its answer to get a better understanding of those properties

这篇关于IOS7:UINavigationController 中的 UIScrollView 偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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