要使用滚动视图的分页效果,通常会配合UIPageControl分页控制控件,以增强分页效果
该控件的常用属性 如下:
相关的代码:
//分页控制控件
_pageControl = [[UIPageControlalloc]init];
//设置大小
_pageControl.bounds =CGRectMake(0,0, 150.0, 50.0);
//设置位置
_pageControl.center =CGPointMake(scrollView.frame.size.width/2, scrollView.frame.size.height-50);
//总页数
[_pageControlsetNumberOfPages:2];
//当前页面
[_pageControlsetCurrentPage:0];
//设置其他页面小圆点的颜色
[_pageControlsetPageIndicatorTintColor:[UIColorwhiteColor]];
[_pageControlsetCurrentPageIndicatorTintColor:[UIColorredColor]];
[self.viewaddSubview:_pageControl];
}
#pragma mark 代理方法实现
/**
* 如果偏移量横坐标超过scrollView的宽就切到第二页 如果没有就切换到第一页
* 页面在滚动时一直在调用
* @param scrollView <#scrollView description#>
*/
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
// if (scrollView.contentOffset.x<50) {
// _pageControl.currentPage = 0;
// }else if(scrollView.contentOffset.x>50){
// _pageControl.currentPage = 1;
// }
//
// }
/**
* 完成减速意味着切换完成
*
* @param scrollView <#scrollView description#>
*/
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
if (scrollView.contentOffset.x<50) {
_pageControl.currentPage =0;
}else if(scrollView.contentOffset.x>50){
_pageControl.currentPage =1;
}
}
//#pragma mark 代理方法的实现
///**
// * 返回值就是要缩放的视图对象
// *
// * @param scrollView <#scrollView description#>
// *
// * @return <#return value description#>
// */
//- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
// return _canyonView;
//}