我已经为此工作了很长一段时间,但我无法弄清楚。
我的页面控件不断消失。
我最初有我的代码,所以它可以工作,但它在滚动视图之间显示页面控件。
我现在怎么改变了它,它在两个视图上向前滚动时显示,而其他视图对页面控件不起作用甚至不显示。当您向后滚动到第一个视图时,页面控件也会消失(包括它在开始运行我的代码时正在处理的两个。
我所有的视图都有相同的设置,所以我不确定为什么会这样。
这是我正在使用的代码的标题:
- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (_pageControlUsed || _rotating) {
// do nothing - the scroll was initiated from the page control, not the user dragging
return;
}
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if (self.pageControl.currentPage != page && page>=0 && page<self.childViewControllers.count) {
UIViewController *oldViewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage];
UIViewController *newViewController = [self.childViewControllers objectAtIndex:page];
[oldViewController viewWillDisappear:YES];
[newViewController viewWillAppear:YES];
self.pageControl.currentPage = page;
[oldViewController viewDidDisappear:YES];
[newViewController viewDidAppear:YES];
_page = page;
CGRect frame = pageControl.frame;
frame.origin.x = pageWidth;
pageControl.frame = frame;
}
}
如果有人知道我哪里出了问题并且可以帮助我,那就太好了。
请注意,我对编程和 xcode 还很陌生。