我知道有几十个关于scrollview的类似问题,但我已经尝试了所有内容,Scrollview
不滚动。
首先,我创建了一个带有xib文件的uiviewcontroller
,并将其设置为自由形式并排列它的大小,并在视图上添加了一个滚动视图。
然后将其作为childviewcontroller
添加到另一个视图控制器。
-(void)scrollViewSetup
{
if (!_scrollView) {
_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,self.scrollView.frame.size.width,200)];
[self.view addSubview:_scrollView];
ScrollView *displayPortf=[[ScrollView alloc] init];
//add as a child view controller here
//displayPortf.delegate=(id)self;
[_scrollView addSubview:displayPortf.view];
[displayPortf didMoveToParentViewController:self];
[self addChildViewController:displayPortf];
}
}
iPad上滚动视图的内容大小为(768,200)
。
我尝试将content size
设置为(1920,200)
,viewDidLoad
没有工作,然后viewDidAppear
没有工作,viewDidLayoutSubviews
没有工作
然后我检查了use auto layout
框并尝试通过editor->resolve auto layout issues->add constraints
如何让scrollview滚动?
注意:父视图使用自动布局和故事板。
答案 0 :(得分:1)
我猜问题的原因是scrollView
的宽度为零
当你这样称呼时:
_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,self.scrollView.frame.size.width,200)];
_scrollView
以宽度self.scrollView.frame.size.width
启动,但此时self.scrollView
为零,因为它与尚未启动的实例变量_scrollView
相关。
尝试为视图宽度设置一些非零浮点值:
_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,768,200)];