iphone - 分页uiscrollview自动滚动到第一页

标签 iphone ios uiscrollview paging

我一直在研究一个带有多个图像的分页 ScrollView 和一个作为目录的表格 View 。 使用表格我可以跳转到特定页面。除了跳转到页面方法之外,我已经完成了所有工作,当我触摸屏幕时,除非我滚动到下一页,否则将 ScrollView 带到第一页。在过去的几天里,它一直让我发疯:s

这是我的代码:

-(void)skipToPage {     
    NSInteger temp = [selectedPage integerValue];   
    [pagingScrollView setContentOffset:
    [self offsetForPageAtIndex:temp] animated:NO];  
    pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; 
}

- (CGPoint)offsetForPageAtIndex:(NSUInteger)index {                                                                                                        
    CGRect pagingScrollViewFrame = [self frameForPagingScrollView];                                                                                        
    CGPoint offset;                                                                                                                                        
    offset.x = (pagingScrollViewFrame.size.width * index);                                                                                                 
    offset.y = 0;                                                                                                                                          
    return offset;                                                                                                                                         
}  

先谢谢大家了!

编辑:scrolviewDidScroll 调用准备要显示的每个图像的 Tile 页面方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self tilePages];   
}

这是来自 Apple 的 photoScroller 示例中的方法

- (void)tilePages 
{
    // Calculate which pages are visible
    CGRect visibleBounds = pagingScrollView.bounds;
    int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
    int lastNeededPageIndex  = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
    firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
    lastNeededPageIndex  = MIN(lastNeededPageIndex, [self imageCount] - 1);

    // Recycle no-longer-visible pages 
    for (ImageScrollView *page in visiblePages) {
        if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
            [recycledPages addObject:page];
            [page removeFromSuperview];
        }
    }
    [visiblePages minusSet:recycledPages];

    // add missing pages
    for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
        if (![self isDisplayingPageForIndex:index]) {
            ImageScrollView *page = [self dequeueRecycledPage];
            if (page == nil) {
                page = [[[ImageScrollView alloc] init] autorelease];
            }
            [self configurePage:page forIndex:index];
            [pagingScrollView addSubview:page];
            [visiblePages addObject:page];
        }
    }

}

最佳答案

我成功了!

问题是由导航 Controller 引起的,它与 PhotoScroller 示例应用程序 react 不佳!解决它使 ScrollView 成为标准 UIView 的 subview ,如:

UIView *view = [[UIView alloc] initWithFrame:pagingScrollViewFrame];
    [view addSubview:pagingScrollView];

    self.view = view;

谢谢:)

关于iphone - 分页uiscrollview自动滚动到第一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5244646/

相关文章:

iphone - 尝试创建函数来计算选中单元格的数量并从另一个函数调用它

iphone - 如何在 iPhone OpenGL ES 中绘制文本

ios - 快速http请求无法获得非200响应

iphone viewForZoomingInScrollView 未调用

ios - UITableView.sizeToFit() 只渲染第一个单元格

php - 返回对象中的 "undefined"字段

iphone - iOS App Documents目录被删除

ios - Flutter-无法从Firebase加载此个人资料图像

ios - CBCentral 连接到 CBPeripheral 无需扫描

ios - Swift:以编程方式添加 UIScrollview 不会在 View 中滚动