这是我对 UIScrollView (iOS 7) 的理解:
contentOffset
定义内容视图的起点contentInset
可以有效地在内容视图周围添加“填充”
在 Xcode 中,我创建了一个单视图应用程序。在 IB 中,我向UIScrollView
视图控制器添加了一个,并将控制器嵌入到导航控制器中。在视图控制器代码中,我添加了以下方法:
- (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,而滚动视图的边界设置为-64?
提前致谢