我正在添加UIScrollView
一个UIViewController
s view
.由于某种原因,在将滚动视图添加到视图并显示之间,将contentOffset
设置为{0, -64}
,64是状态栏的20加上导航栏的44点(我猜).下面是一些重现问题的代码和图像.
如何阻止iOS设置contentOffset
?
- (void)viewDidLoad { [super viewDidLoad]; _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 100, 100, 100)]; _scroll.backgroundColor = [UIColor greenColor]; _scroll.delegate = self; UIView *red = [[UIView alloc] initWithFrame:CGRectMake(0, 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)); }
设置automaticallyAdjustsScrollViewInsets
您的视图控制器上NO
,否则它会在它的第一子视图调整插图这么恰巧是根视图UIScrollView
类.
有关iOS 7 Transition Guide的更多信息.