gpt4 book ai didi

ios - contentOffset 和 contentInset 如何在 iOS 7 中为 UIScrollView 工作?

转载 作者:行者123 更新时间:2023-11-29 12:47:06 32 4
gpt4 key购买 nike

这是我对 UIScrollView (iOS 7) 的理解:

  • contentOffset 定义内容 View 的原点
  • contentInset 可以有效地在内容 View 周围添加“填充”

在 Xcode 中,我创建了一个单 View 应用程序。在 IB 中,我向 View Controller 添加了一个 UIScrollView,并将 Controller 嵌入到导航 Controller 中。在 View Controller 代码中,我添加了以下方法:

- (void)viewDidAppear:(BOOL)animated
{
[self.scrollView setContentSize:CGSizeMake(380, 1000)];
NSLog(@"top = %f, bounds top %f", self.scrollView.frame.origin.y, self.scrollView.bounds.origin.y);
NSLog(@"offset y = %f", self.scrollView.contentOffset.y);
NSLog(@"height = %f", self.scrollView.contentSize.height);
NSLog(@"inset top = %f", self.scrollView.contentInset.top);
NSLog(@"inset bottom = %f", self.scrollView.contentInset.bottom);
}

我的结果:

top = 0.000000, bounds top -64.000000
offset y = -64.000000
height = 1000.000000
top = 64.000000
bottom = 0.000000

contentInset.top 值有效地将内容向下移动,使其位于导航栏下方。为什么 contentOffset.y 设置为 -64,而 ScrollView 的边界设置为 -64?

提前致谢

最佳答案

因为 automaticallyAdjustsScrollViewInsets 默认值在 iOS 7.0 中是 YES

The default value of this property is YES, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s view to account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property to NO if your view controller implementation manages its own scroll view inset adjustments.

UIViewController Class Reference

关于ios - contentOffset 和 contentInset 如何在 iOS 7 中为 UIScrollView 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23435254/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com