gpt4 book ai didi

ios - UIScrollview 不滚动

转载 作者:行者123 更新时间:2023-11-29 02:57:41 25 4
gpt4 key购买 nike

我知道有数十个关于 ScrollView 的类似问题,但我已经尝试了所有方法,Scrollview 不滚动。

首先,我用一个 xib 文件创建了一个 uiviewcontroller,并将其设置为自由格式并调整它的大小,并在 View 上添加了一个 ScrollView 。

enter image description here

然后将其作为 childviewcontroller 添加到另一个 View Controller 。

-(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 上 ScrollView 的内容大小为 (768,200)。我尝试在 viewDidLoad 中将 content size 设置为 (1920,200) 没有用,然后 viewDidAppear 没有工作,然后 viewDidLayoutSubviews 不起作用。

然后我检查了 use auto layout 框并尝试通过 editor->resolve auto layout issues->add constraints 添加常量

如何让scrollview滚动?

注意:父 View 使用自动布局和 Storyboard。

最佳答案

我猜问题的原因是 scrollView 的宽度为零。
当你这样调用它时:

_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,self.scrollView.frame.size.width,200)];

_scrollView 以宽度 self.scrollView.frame.size.width 启动,但此时 self.scrollView 为 nil 因为它与尚未启动的实例变量 _scrollView 相关。

尝试为 View 宽度设置一些非零浮点值:
_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,768,200)];

关于ios - UIScrollview 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23703785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com