我遇到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
不会随当前页面移动。
答案 0 :(得分:0)
你可以看看这篇博客文章:http://mobileappdev.learningtree.com/2012/12/18/paging-with-collection-views-part-2/ ...我只是用它来设置我的UIPageControl元素,它运行正常。您可能需要根据您的特定需求进行调整......