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

查看:181
本文介绍了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.

现在好了,我不知道如何使用界面构建器正确设计。
我还有我的片段来初始化我的navcontroller。但是在我的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_________________________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.

感谢您的帮助


编辑

正如我们在图片中看到的那样,视图的第一个子节点是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)

我找到的唯一文件是:

  • https://web.archive.org/web/20160405135605/https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html
  • https://developer.apple.com/documentation/uikit/uiviewcontroller/1621372-automaticallyadjustsscrollviewin

更新

在iOS 11中不建议使用adsAdjustsScrollViewInsets

您现在应该使用:

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天全站免登陆