gpt4 book ai didi

ios - UIScrollView 停止工作添加 subview

转载 作者:行者123 更新时间:2023-11-29 04:23:05 26 4
gpt4 key购买 nike

我在使用 UIScrollView.i 时遇到一些问题。我创建它,设置一些属性,并使用主视图指向此 UIScrollView.See:

scrollWidth = 320.0;
scrollHeight = 410 * listRegisterPeople.count;
scrollScreenView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, scrollWidth, scrollHeight)];
[scrollScreenView setScrollEnabled:YES];
[scrollScreenView setContentSize:CGSizeMake(scrollWidth, 410 * list.count)];
[scrollScreenView setShowsVerticalScrollIndicator:YES];
[scrollScreenView setShowsHorizontalScrollIndicator:YES];
[scrollScreenView setPagingEnabled:NO];
scrollScreenView.delegate = self;
[scrollScreenView setContentOffset:CGPointMake(0, 0)];
self.view = scrollScreenView;

但我想添加scrollScreenView作为 subview [self.view addSubview:scrollScreenView]。但通过这种方式我无法滚动我的 View ,我不知道为什么。 . .

如何解决?

最佳答案

如果ScrollView的框架大于或等于内容大小,则不会滚动。您的 ScrollView 高度等于 ScrollView contentSize ,我认为这就是问题所在。使框架等于 self.view 并设置内容大小,如下所示:尝试以下操作。

scrollWidth = 320.0;
scrollHeight = 410 * listRegisterPeople.count;
scrollScreenView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320,self.view.frame.size.height)];
[scrollScreenView setScrollEnabled:YES];
[scrollScreenView setContentSize:CGSizeMake(scrollWidth, scrollHeight)];
[scrollScreenView setShowsVerticalScrollIndicator:YES];
[scrollScreenView setShowsHorizontalScrollIndicator:YES];
[scrollScreenView setPagingEnabled:NO];
scrollScreenView.delegate = self;
[scrollScreenView setContentOffset:CGPointMake(0, 0)];
[self.view addSubview:scrollScreenView];

关于ios - UIScrollView 停止工作添加 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12708801/

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