agg*_*n64 9 iphone uiscrollview uipagecontrol
我搜索并搜索了一个教程,但没有一个是我正在寻找的.我试过Apple的样本,但它只是颜色,我不知道如何使它的观点.我正在寻找的是一个屏幕,在显示页面控件时会翻页.每次滚动视图页面我希望它显示完全不同的视图.不同的文字或图像,但不同的视图.很像iPhone的主屏幕或ESPN Scorecenter应用程序.请帮忙!谢谢.
Ren*_*tik 16
我创建了这个通用的解决方案,因为发现的例子很复杂,这对我来说是可读的,代码应该是自我解释的.
- (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));
}
Run Code Online (Sandbox Code Playgroud)
dat*_*inc 14
这与@ReneDohan的答案相同,无需变量来存储状态
- (IBAction)changePage:(id)sender {
CGFloat x = self.pageControl.currentPage * self.scrollView.frame.size.width;
[self.scrollView setContentOffset:CGPointMake(x, 0) animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.isDragging || scrollView.isDecelerating){
self.pageControl.currentPage = lround(self.scrollView.contentOffset.x / (self.scrollView.contentSize.width / self.pageControl.numberOfPages));
}
}
Run Code Online (Sandbox Code Playgroud)
有一个相关的问题:如何使用 UIPageControl 创建多个视图?,这篇博客文章解释了一个非常好的方法:http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html。
| 归档时间: |
|
| 查看次数: |
23322 次 |
| 最近记录: |