The problem shows in the gif picture.(黄色视图是内容视图。黑色视图是滚动视图。)
The whole project code on Github.
以下是代码:
CGRect frame = CGRectMake( 50, 100, 200, 200);
UIScrollView *scrollView= [[UIScrollView alloc] initWithFrame:frame];
[self.view addSubview:scrollView];
frame= CGRectMake( 0, 0, 500, 500);
UIImageView *myImageView= [[UIImageView alloc] initWithFrame:frame];
[scrollView addSubview:myImageView];
scrollView.contentSize = CGSizeMake(500,500);
scrollView.backgroundColor = [UIColor blackColor];
myImageView.backgroundColor = [UIColor yellowColor];
scrollView.contentOffset = CGPointMake(0, 0)
图中还显示了一个问题: 为什么水平滚动条不在scrollview的底部?
当我在scrollview和self.view之间添加一个视图时,问题就消失了。
我添加的代码:
UIView *view = [UIView new];
[self.view addSubview:view];
我发现问题发生在我使用UITabBarController时。
答案 0 :(得分:0)
使UIScrollView成为全局变量。当像这样加载视图时,使UIScrollView和UIScrollView的指标UIEdgeInsetsZero的contentInset:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_scrollView.contentInset = UIEdgeInsetsZero;
_scrollView.scrollIndicatorInsets = UIEdgeInsetsZero;
}