以编程方式导航到scrollView中的特定页面 [英] Navigate to specific page in scrollView with paging, programmatically

查看:130
本文介绍了以编程方式导航到scrollView中的特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式导航到特定页面。基本上我有一个带有scrollView的应用程序,其中填充了一堆子视图(在本例中为tableViews)。当点击子视图时,它会放大并且用户可以编辑和导航表格,但是当我缩小时,我会重新加载整个视图,以防用户做出任何更改。当然重新加载视图会将用户返回到第0页。我已经尝试设置pageControl.currentpage属性,但所有这一切都改变了pageControl的点。这是否意味着出现了问题,或者我是否还需要做其他事情?

How do I navigate to a specific page programmatically. Basically I have an app with a scrollView populated with a bunch of subviews (tableViews in this case). When clicking on a subview it zooms in and the user can edit and navigate the table, however when I zoom back out I reload the entire view in case there were any changed made by the user. Of course reloading the view sends the user back to page 0. I've tried setting the pageControl.currentpage property but all that does is change the dot of the pageControl. Does that mean that something is wrong or do I need to do something else as well??

所有控制页面滚动的方法都是这种方法:

All that is controlling the page scrolling is this method:

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

NSString *listName = [self.wishLists objectAtIndex:self.pageControl.currentPage];
self.labelListName.text = listName;
}


推荐答案

你必须计算相应的手动滚动位置。要滚动到第i页:

You have to calculate the corresponding scroll position manually. To scroll to page i:

[scrollView setContentOffset:CGPointMake(scrollView.frame.size.width*i, 0.0f) animated:YES];

这篇关于以编程方式导航到scrollView中的特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆