UICollectionView :屏幕外自动滚动以进行分页 [英] UICollectionView : Offscreen auto scroll for paging

查看:42
本文介绍了UICollectionView :屏幕外自动滚动以进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下代码滚动我的应用程序中屏幕外的 UICollectionView.

I am trying to scroll UICollectionView which is offscreen in my app, by below code.

int pages = ceil(aCollectionView.contentSize.height / aCollectionView.frame.size.height);

for (int i = 0; i < pages; i ++)
{
     NSArray *sortedVisibleItems = [[aCollectionView indexPathsForVisibleItems] sortedArrayUsingSelector:@selector(compare:)];

     NSIndexPath *lastItem = [sortedVisibleItems lastObject];

     // 2.next position
     NSInteger nextItem = lastItem.item + 1;
     NSInteger nextSection = lastItem.section;
     NSIndexPath *nextIndexPath = [NSIndexPath indexPathForItem:nextItem inSection:nextSection];

     [self takeImage];

     dispatch_async(dispatch_get_main_queue(), ^
    {            
        [aCollectionView scrollToItemAtIndexPath:nextIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
    });
}

并为打印目的拍摄每一页的屏幕截图.但它不滚动并且总是多次打印第一页.

And taking screen shots of each page for printing purpose. But its not scrolling and always prints the 1st page multiple times.

UICollectionView 的属性

UICollectionView's property

我是否遗漏了或做错了?

Am I missing or doing in wrong direction ?

推荐答案

集合视图仅在主线程上更新.您的代码被包装在一个循环中,它永远不允许主线程运行和更新.

A collection view only updates on the main thread. Your code is wrapped in a loop, which never allows the main thread to run and update.

有很多关于这个的讨论.许多与使用 UIScrollView 做同样的事情直接相关,但这是同样的问题.

There are lots of discussions about this out there. Many related directly to doing the same thing with UIScrollView, but it's the same issue.

您可能想看看这个...不确定它是否适合您的需求,但我已经多次看到它被引用:https://github.com/sgr-ksmt/PDFGenerator

You might want to look at this... not sure if it will fit your needs, but I've seen it referenced multiple times: https://github.com/sgr-ksmt/PDFGenerator

如果这对您不起作用,它可能具有您需要的技术,因此对该代码进行一些调查应该会找到您的答案.

If that doesn't work for you, it probably has the technique you need in it, so a little investigating of that code should find your answer.

这篇关于UICollectionView :屏幕外自动滚动以进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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