我有这个设置:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 1000.0)];
scroll.backgroundColor = [UIColor clearColor];
scroll.contentSize = CGSizeMake(320.0, 1000.0);
[self.view addSubview:scroll];
UIView *pView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 100.0, 300.0, 400.0)];
pView.backgroundColor = [UIColor whiteColor];
pView.layer.cornerRadius = 2.0;
pView.layer.borderColor = [UIColor blueColor].CGColor;
pView.layer.borderWidth = 1.0f;
[scroll addSubview:pView];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 500.0, 300.0, 20.0)];
aView.backgroundColor = [UIColor redColor];
[scroll addSubview:aView];
但是,每当我向下滚动视图时,屏幕就会弹回顶部。为什么?
最佳答案
不要将您的scrollview高度设置为大于屏幕尺寸-滚动的不是scrollView,而是滚动视图中的内容。