简体   繁体   English

如何检测UIScrollView的下一页编号,即'scrollView.pagingEnabled'= YES? 在'scrollViewDidEndDragging'?

[英]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 :) 请给我一些帮助:)

EDIT 编辑

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.

相关问题 如何设置带有寻呼启用=是的UIScrollView的页面调度行为? - How can I set the paging behavior of an UIScrollView with pagingEnabled=YES? 无法使用 UIScrollView 和 pagingEnabled=YES 禁用反弹 - Can't disable bounce with UIScrollView and pagingEnabled=YES ios uiscrollview与uiimageviews之间启用分页如何检测屏幕上/可见 - ios uiscrollview with pagingenabled between uiimageviews how to detect which one is on the screen/visible UIScrollView - (bounces = NO)似乎覆盖(pagingEnabled = YES) - UIScrollView - (bounces = NO) seems to override (pagingEnabled = YES) 当带有 PagingEnabled 的 UIScrollView 更改页面时如何更新 UIPageControl? - How to update UIPageControl when UIScrollView with PagingEnabled changes page? UIScrollView无法与[scrollView setScrollEnabled:是]一起使用 - UIScrollView not working with [scrollView setScrollEnabled: YES] 检测在页面启用的UIScrollView中正在显示哪个UIView - Detecting which UIView is being displayed within a pagingEnabled UIScrollView PagingEnabled 为 UIScrollView 中的多个页面启用 - PagingEnabled for multiple pages in UIScrollView UITextView&pagesEnabled:如何正确“翻页” - UITextView & pagingEnabled: how to 'turn the page' properly 问题IIS 3.1.3中的UIScrollView pagingenabled - Problem UIScrollView pagingenabled in IOS 3.1.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM