1/判斷滾動視圖左右滾動
{
CGFloat startContentOffsetX;//滾動開始的坐標
CGFloat willEndContentOffsetX; //滾動即將停止的坐標
CGFloat endContentOffsetX;//滾動結束的坐標
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ myPC.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width; currNum = (int)myPC.currentPage; } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ startContentOffsetX = scrollView.contentOffset.x; [self stopTimer]; } - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{ //將要停止前的坐標 willEndContentOffsetX = scrollView.contentOffset.x; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ endContentOffsetX = scrollView.contentOffset.x; if (endContentOffsetX < willEndContentOffsetX && willEndContentOffsetX < startContentOffsetX) { //畫面從右往左移動,前一頁 isNext = NO; } else if (endContentOffsetX > willEndContentOffsetX && willEndContentOffsetX > startContentOffsetX) {//畫面從左往右移動,后一頁 isNext = YES; } [self starTimer]; }
2/判斷上下滾動視圖上下滾動
float lastContentOffset;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
lastContentOffset = scrollView.contentOffset.y;
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
if (lastContentOffset < scrollView.contentOffset.y) {
NSLog(@"向上滾動");
}else{
NSLog(@"向下滾動");
}
}
