【问题标题】:How to Make the scrollview, scroll in specific page when scrolled iOS如何制作滚动视图,滚动iOS时在特定页面中滚动
【发布时间】:2014-08-21 08:40:26
【问题描述】:

我正在尝试以编程方式在特定页面上滚动滚动视图。我还为 and 使用了 pageControl,并且效果很好。我在滚动时遇到问题。

这是我创建滚动视图的方式:

contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, lengthBarView.frame.size.height + lengthBarView.frame.origin.y, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height - 143)];
contentScrollView.backgroundColor = [UIColor greenColor];
[self addSubview:contentScrollView];

以下是我创建 Page 控件的方法:

self.pageControl = [[UIPageControl alloc] init] ;
self.pageControl.frame = CGRectMake(110,385,100,20);
self.pageControl.currentPage = 0;
[self.pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.pageControl];
pageControl.pageIndicatorTintColor = [UIColor redColor];

这是我的页面控件功能的代码:

- (void)changePage:(id)sender {
// update the scroll view to the appropriate page

[secondTabNextView.contentScrollView endEditing: YES];
CGRect frame;
frame.origin.x = secondTabNextView.contentScrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = secondTabNextView.contentScrollView.frame.size;
[secondTabNextView.contentScrollView scrollRectToVisible:frame animated:YES];
}

这是我的滚动视图代码:

- (void)scrollViewDidScroll:(UIScrollView *)sender {
CGFloat pageWidth = secondTabNextView.contentScrollView.frame.size.width;
int page = floor((secondTabNextView.contentScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}

如何在特定页面中滚动,就像从幻灯片中拖动图片一样。

【问题讨论】:

    标签: ios uiscrollview uipagecontrol


    【解决方案1】:

    终于修好了,我只是忘了在我的滚动视图中添加分页和滚动功能:

    contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, lengthBarView.frame.size.height + lengthBarView.frame.origin.y, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height - 143)];
    contentScrollView.backgroundColor = [UIColor greenColor];
    contentScrollView.scrollEnabled = YES;
    contentScrollView.pagingEnabled = YES;
    [self addSubview:contentScrollView];
    

    【讨论】:

      猜你喜欢
      • 2023-04-11
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多