使用UIScrollView时我遇到一些问题。创建它,设置一些属性,并使用主视图指向这个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添加为子视图[self.view addSubview:scrollScreenView]。但通过这种方式我不能滚动我的观点,我不知道为什么。 。 。
如何解决?
答案 0 :(得分:1)
如果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];
答案 1 :(得分:0)
我认为你应该替换
行self.view = scrollScreenView;
为行
[self.view addSubview:scrollScreenView]
答案 2 :(得分:0)
Autolayout在视图加载后设置了一些约束,因此,只需将内容大小放入 viewDidAppear,你的代码不会被重写。
这对我有用。
-(void)viewDidAppear:(BOOL)animated{
[self.scrollView setContentSize:CGSizeMake(320, 1000)];
}
抱歉我的英语不好。