1.创建两个全局变量,并遵循UIScrollerview的代理
@property(nonatomic,strong)UIScrollView* scrollerview;
@property(nonatomic,strong)UIPageControl* pagenumber;
2.在需要的地方初始,设置初始值,设置UIScrollerView的pagingEnabled属性为YES,contentSize,delegate,Frame。UIPageeControl添加相应方法为:addTarget
3.在UIScrollerView的代理方法如下代码
- (void)scrollViewDidScroll:(UIScrollView*)scrollView{
NSLog(@"222");
CGFloatpageWidth =_scrollerview.frame.size.width;
//在滚动超过页面宽度的50%的时候,切换到新的页面
int page =floor((_scrollerview.contentOffset.x+ pageWidth/2)/pageWidth) ;
self.pagenumber.currentPage= page;
}
4、UIPageeControl的相应方法
- (void)pageaction:(UIPageControl*)sender{
CGRectframe;
frame.origin.x=_scrollerview.frame.size.width*_pagenumber.currentPage;
frame.origin.y=0;
frame.size=_scrollerview.frame.size;
[_scrollerviewscrollRectToVisible:frameanimated:YES];
}