//
视图控制器
把
scroll
的预留导航栏的距离关掉
[self setAutomaticallyAdjustsScrollViewInsets:NO];
//scrollView的协议方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"任何谝移量的改变都会调用这个方法");
}最重要!!!
self
.
pageControl
= [[
UIPageControl
alloc
]
initWithFrame
:
CGRectMake
(
20
,
400
,
280
,
40
)];
[ self . view addSubview : self . pageControl ];
self . pageControl . backgroundColor = [ UIColor clearColor ];
// 设置白点的数量
self . pageControl . numberOfPages = 3 ;
self . pageControl . pageIndicatorTintColor = [ UIColor grayColor ];
// 当值改变时调用的方法
[ self . pageControl addTarget : self action : @selector (pageAction:) forControlEvents : UIControlEventValueChanged ];
[ self . pageControl release ];
[ self . view addSubview : self . pageControl ];
self . pageControl . backgroundColor = [ UIColor clearColor ];
// 设置白点的数量
self . pageControl . numberOfPages = 3 ;
self . pageControl . pageIndicatorTintColor = [ UIColor grayColor ];
// 当值改变时调用的方法
[ self . pageControl addTarget : self action : @selector (pageAction:) forControlEvents : UIControlEventValueChanged ];
[ self . pageControl release ];
- (
void
)scrollViewDidScroll:(
UIScrollView
*)scrollView
{
// 只要 scrollview 一滚动 就调用这个方法
NSLog ( @" 谝移量 : %f" , scrollView. contentOffset .x);
int page = scrollView. contentOffset . x / scrollView. frame . size . width ;
self . pageControl . currentPage = page;
}
- ( void )pageAction:( UIPageControl *)pageControl
{
NSLog ( @" 翻页 " );
// 显示当前页数,从零开始
NSLog ( @"%d" ,pageControl. currentPage );
// _scrollViewMain.contentOffset = CGPointMake( 280 * pageControl.currentPage, 0);
// 调整谝移量的一个动画效果
[ _scrollViewMain setContentOffset : CGPointMake ( 280 *pageControl. currentPage , 0 ) animated : YES ];
}
{
// 只要 scrollview 一滚动 就调用这个方法
NSLog ( @" 谝移量 : %f" , scrollView. contentOffset .x);
int page = scrollView. contentOffset . x / scrollView. frame . size . width ;
self . pageControl . currentPage = page;
}
- ( void )pageAction:( UIPageControl *)pageControl
{
NSLog ( @" 翻页 " );
// 显示当前页数,从零开始
NSLog ( @"%d" ,pageControl. currentPage );
// _scrollViewMain.contentOffset = CGPointMake( 280 * pageControl.currentPage, 0);
// 调整谝移量的一个动画效果
[ _scrollViewMain setContentOffset : CGPointMake ( 280 *pageControl. currentPage , 0 ) animated : YES ];
}