标签:
起始偏移量设置为一个宽度
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(refreshPic) userInfo:nil repeats:YES];
//定时器实现
- (void)refreshPic{
if (_mainScrollView.contentOffset.x/_mainScrollView.frame.size.width==4) {
_mainScrollView.contentOffset = CGPointMake(0, 0);
}
[_mainScrollView setContentOffset:CGPointMake(_mainScrollView.frame.size.width+_mainScrollView.contentOffset.x, 0) animated:YES];
self.pageCor.currentPage = _mainScrollView.contentOffset.x/_mainScrollView.frame.size.width;
}
//手动拖拽实现
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
if (_mainScrollView.contentOffset.x/_mainScrollView.frame.size.width == 5) {
_mainScrollView.contentOffset = CGPointMake(_mainScrollView.frame.size.width, 0);
self.pageCor.currentPage = 0;
}else if (_mainScrollView.contentOffset.x/_mainScrollView.frame.size.width==0){
_mainScrollView.contentOffset = CGPointMake(_mainScrollView.frame.size.width*4, 0);
self.pageCor.currentPage = 3;
}else{
self.pageCor.currentPage = _mainScrollView.contentOffset.x/_mainScrollView.frame.size.width-1;
}
//定时器触碰停止,3秒后自动启动
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
_timer.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
}
}
标签:
原文地址:http://www.cnblogs.com/block123/p/4912383.html