在uiscrollview中有三個不同的頁面視圖控制器用作視圖。帶頁面控件的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串聯。
感謝您的幫助。
你是非常正確的。這是一個小問題,但我錯過了。都謝謝你。感謝你的幫助。 – user1120133