【问题标题】:uiscrollview into pages and move between the pages using an up and down buttonuiscrollview 进入页面并使用向上和向下按钮在页面之间移动
【发布时间】:2011-08-04 13:02:40
【问题描述】:

我需要将滚动视图放入页面并使用向上和向下按钮在页面之间移动。

如何通过按钮实现页面间的移动?

【问题讨论】:

    标签: iphone uiscrollview pagination uibutton


    【解决方案1】:

    创建要调用的 changePage 方法 - 与通常使用 pageControl 的方法相同。

    如果您以前没有这样做,我建议您尝试使用 pageControl 实现,然后在完成排序后切换到按钮。

    -(IBAction)changePage:(id)sender {
    
     CGRect frame = scroll.frame;
    
     frame.origin.x = frame.size.width * pageControl.currentPage;
    
     frame.origin.y = 0;
    
     [scroll scrollRectToVisible:frame animated:YES];
    
     pageControlIsChangingPage = YES;
    
    }
    
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView  {
    
     pageControlIsChangingPage = NO;
    
    CGFloat pageWidth = _scrollView.frame.size.width;
    
     int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    
     pageControl.currentPage = page;
    
    }
    
    
    -(void)scrollViewDidScroll:(UIScrollView *)_scrollView {
    
        if (pageControlIsChangingPage) {
    
            return;
    
        }
    
        CGFloat pageWidth = _scrollView.frame.size.width;
    
        int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    
        pageControl.currentPage = page;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多