在 uiscrollview 中使用三个不同的页面视图控制器作为视图。带有 pagecontrol 的 UIScrollView 仅将第三页显示为当前页面,但不显示其他两个页面。页面控件也不可见。
- (void)viewDidLoad
{
[super viewDidLoad];
PageOne *pageOne = [[PageOne alloc] init];
pageOne.view.frame = CGRectMake(0, 0, 320, 420);
PageTwo *pageTwo = [[PageTwo alloc]init];
pageTwo.view.frame = CGRectMake(0, 0, 320, 420);
PageThree *pageThree = [[PageThree alloc] init];
pageThree.view.frame = CGRectMake(0, 0, 320, 420);
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width * 3, self.view.frame.size.height)];
[scrollView setDelegate:self];
[scrollView setPagingEnabled:YES];
[scrollView setShowsHorizontalScrollIndicator:YES];
[scrollView addSubview:pageOne.view];
[scrollView addSubview:pageTwo.view];
[scrollView addSubview:pageThree.view];
[self.view addSubview:scrollView];
_pageControl = [[UIPageControl alloc] init];
[_pageControl setCurrentPage:0];
[_pageControl setNumberOfPages:3];
[_pageControl sizeToFit];
[_pageControl setFrame:CGRectMake((scrollView.frame.size.width / 2) - (_pageControl.frame.size.width / 2), scrollView.frame.size.height - _pageControl.frame.size.height, _pageControl.frame.size.width, _pageControl.frame.size.height)];
[self.view addSubview:self.pageControl];
[super viewDidLoad];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
_pageControl.currentPage = lround(scrollView.contentOffset.x / scrollView.frame.size.width);
}
现在它只显示 pageThree。为什么不显示 pageOne 和 pageTwo。
为什么不依次显示 PageOne、pageTwo 和 pageThree。
感谢帮助。