UIPageControl 指示点在页面更改时不会更改
Posted
技术标签:
【中文标题】UIPageControl 指示点在页面更改时不会更改【英文标题】:UIPageControl indicator dot does not change when the page changes 【发布时间】:2014-03-06 21:17:01 【问题描述】:我遇到了UIPagecotrol
的问题。它没有在模拟器中激活。点不会更改到下一个视图。
- (void)viewWillAppear:(BOOL)animated
[super viewWillAppear:animated];
for (NSUInteger i =0; i < [self.childViewControllers count]; i++)
[self loadScrollViewWithPage:i];
self.pageControl.currentPage = 0;
_page = 0;
[self.pageControl setNumberOfPages:[self.childViewControllers count]];
UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage];
if (viewController.view.superview != nil)
[viewController viewWillAppear:animated];
self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [self.childViewControllers count], scrollView.frame.size.height);
- (void)loadScrollViewWithPage:(int)page
if (page < -0)
return;
if (page >= [self.childViewControllers count])
return;
// replace the placeholder if necessary
UIViewController *controller = [self.childViewControllers objectAtIndex:page];
if (controller == nil)
return;
// add the controller's view to the scroll view
if (controller.view.superview == nil)
CGRect frame = self.scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[self.scrollView addSubview:controller.view];
// At the begin of scroll dragging, reset the boolean used when scrolls originate from the UIPageControl
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
_pageControlUsed = NO;
// At the end of scroll animation, reset the boolean used when scrolls originate from the UIPageControl
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
_pageControlUsed = NO;
- (IBAction)changePage:(id)sender;
这里的源代码:https://mega.co.nz/#F!0EkBQbTK!bKjEwFf7BQsUx0YGtoHehw
只需以 zip 格式下载并在 Xcode 中运行。请注意,UIPageControl
不会随当前页面移动。
【问题讨论】:
【参考方案1】:你可以看看这篇博客文章:http://mobileappdev.learningtree.com/2012/12/18/paging-with-collection-views-part-2/ ...我只是用它来设置我的 UIPageControl 元素,它工作正常。您可能需要根据您的特定需求对其进行一些调整...
【讨论】:
以上是关于UIPageControl 指示点在页面更改时不会更改的主要内容,如果未能解决你的问题,请参考以下文章
如何用每页不同的颜色更改 UIPageControl 中分页点的颜色
UIPageControl 当前页面指示器在显示新视图之前切换