如何将UIScrollview与UIPagecontrol结合使用以显示不同的视图? [英] How do you combine UIScrollview with UIPagecontrol to show different views?
问题描述
我搜索并搜索了这方面的教程,但没有一个是我正在寻找的。我尝试过Apple的样本,但它只是颜色,我不知道如何使它成为观点。我正在寻找的是一个屏幕,在显示页面控件时会翻页。每次滚动视图页面我希望它显示完全不同的视图。不同的文字或图像,但不同的视图。很像iPhone的主屏幕或ESPN Scorecenter应用程序。请帮忙!
谢谢。
I've searched and searched for a tutorial for this but none of them are what I'm looking for. I've tried Apple's sample but it is just colors and I don't know how to make it views. All I'm looking for is a screen that will page while showing the page control. Each time the scroll view pages i want it to show a completely different view. Not different text or images but a different view. A lot like the home screen of the iPhone or ESPN Scorecenter app. Please Help! Thank you.
推荐答案
我创建了这个通用解决方案,因为发现的例子很复杂,这对我来说是可读的,代码应该是自我解释的。
I created this universal solution as examples found was to complicated and this is readable for me, code should be self explanatory.
- (IBAction)changePage:(id)sender {
_pageControlUsed = YES;
CGFloat pageWidth = _scrollView.contentSize.width /_pageControl.numberOfPages;
CGFloat x = _pageControl.currentPage * pageWidth;
[_scrollView scrollRectToVisible:CGRectMake(x, 0, pageWidth, _scrollView.frame.size.height) animated:YES];
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
_pageControlUsed = NO;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (!_pageControlUsed)
_pageControl.currentPage = lround(_scrollView.contentOffset.x /
(_scrollView.contentSize.width / _pageControl.numberOfPages));
}
这篇关于如何将UIScrollview与UIPagecontrol结合使用以显示不同的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!