[英]How can I detect next page number of UIScrollView which is 'scrollView.pagingEnabled' = YES? in 'scrollViewDidEndDragging'?
I searched several stuffs on stackoverflow like 我在stackoverflow上搜索过几个东西
CGFloat pageWidth = scrollView.frame.size.width;
int pageNumberToBeScrolled = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if (pageNumberToBeScrolled != 1) {
// Do what I want
}
in 在
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
But this works only if I scrolled slowly so scrolling page is definitely moved over half of it. 但这只有在我慢慢滚动时才有效,因此滚动页面肯定会移动一半以上。 This doesn't work if I scrolled fast like swipe. 如果我像滑动一样快速滚动,这不起作用。 I just scrolled like 30% of scrolling page, which doesn't satisfy the situation over there, but it scrolled to next page, and I want to detect it. 我只是滚动了30%的滚动页面,这不满足那里的情况,但它滚动到下一页,我想检测它。
How can I detect or catch all scroll-to-next-page
situations? 如何检测或捕获所有scroll-to-next-page
情况? Please give me some help :) 请给我一些帮助:)
I working on this because I want to play a effect sound when scroll-to-next-page happens. 我正在研究这个因为我想在滚动到下一页时发出效果声。 I should detect right after my finger is off the screen and only for next page scrolling. 我应该在我的手指离开屏幕后立即检测到并且仅用于下一页滚动。 I think if I handle this on scrollViewDidEndDragging
, it'll be best for me :) 我想如果我在scrollViewDidEndDragging
上处理它,它对我来说最好:)
I'm using this code to detect if currentPage is changed, it doesn't matter you scroll very fast or very slow. 我正在使用此代码来检测currentPage是否已更改,滚动速度非常快或非常慢也无关紧要。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
static NSInteger previousPage = 0;
CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSInteger page = lround(fractionalPage);
NSLog(@"%d",page);
if (previousPage != page) {
previousPage = page;
/* Page did change */
}
}
try like this may be it'l helps you 尝试这样可能会帮助你
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
float fractionalPage = scrollView.contentOffset.x / 320;
NSInteger page1 = lround(fractionalPage);
NSLog(@"%d",page1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.