我正在将UIScrollView添加到UIViewControllers视图中.出于某种原因,在将滚动视图添加到视图并显示之间,contentOffset设置为{0,-64},64是状态栏的20加上导航栏的44点(我猜).下面是一些重现问题的代码和图像.
如何阻止iOS设置contentOffset?
- (void)viewDidLoad
{
[super viewDidLoad];
_scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(10,100,100)];
_scroll.backgroundColor = [UIColor greenColor];
_scroll.delegate = self;
UIView *red = [[UIView alloc] initWithFrame:CGRectMake(0,10,10)];
red.backgroundColor = [UIColor redColor];
[_scroll addSubview:red];
[self.view addSubview:_scroll];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// outputs {0,-64}
NSLog(@"%@",NsstringFromCGPoint(_scroll.contentOffset));
}
解决方法
将视图控制器上的automaticAdjustsScrollViewInsets设置为NO,否则它将在其根视图的第一个子视图上调整插件,该视图恰好是UIScrollView类.
更多关于iOS 7 Transition Guide的内容.