Tag: uicollectionview

UICollectionView与CustomFlowLayout如何限制每滚动只有一个页面滚动?

我在我的iOS应用程序中实现了customFlowLayout 。 我已经通过子类化UICollectionViewFlowLayout子类化了targetContentOffsetForProposedContentOffset:withScrollingVelocity UICollectionViewFlowLayout 。 现在我的问题是当用户滚动collectionview它必须滚动到只有下一个索引。 现在它随机滚动。 所以任何人都有任何想法,我怎样才能使滚动限制只有一个项目每卷。 以下是我的代码。 #pragma mark – UICollectionViewLayout (UISubclassingHooks) – (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity { CGSize collectionViewSize = self.collectionView.bounds.size; CGFloat proposedContentOffsetCenterX = proposedContentOffset.x + collectionViewSize.width / 2; CGRect proposedRect = CGRectMake(proposedContentOffset.x, 0, collectionViewSize.width, collectionViewSize.height); UICollectionViewLayoutAttributes *candidateAttributes; for (UICollectionViewLayoutAttributes *attributes in [self layoutAttributesForElementsInRect:proposedRect]) { if (attributes.representedElementCategory != UICollectionElementCategoryCell) continue; if (!candidateAttributes) { candidateAttributes […]

animationUICollectionViewCell折叠

我试图在用户点击它时animationUICollectionViewCell的高度。 基本function按预期工作。 它挖掘和扩大点击时,但我的UICollectionViewCells自定义,并有一个headerView和一个contentView,所以当我animation的高度它折叠contentView为0,只有头是可见的,反之亦然扩大。 问题是,contentView只是在那里/消失,并不是作为单元格(它的超级视图本身)的animation。 查看截图以获得更好的理解: 点击标题(红色)时的animation。 contentView是即时可见的,但单元格在它后面有animation: animation完成后,一切都很好: 按照预期再次敲击单元格,但contentView(蓝色)瞬间隐藏: 通过在collectionViewLayout上执行批量更新来完成实现。 我认为它只是一个小旗子,但我现在正在寻找一段时间。 编辑:禁用自定义UICollectionViewCell中的自动布局后,它的工作完美,但这似乎更像是一个解决方法给我。 所以我会打开这个问题。

UIScrollView委托方法调用不正确

为了上下滚动我需要调用两个方法,我已经使用了下面的方法。我使用UICollection的scrollview委托方法 ,因为它是UIScrollView的子视图。这里是我写的代码,但滚动是不容易移动,结果也不准确,有时可以有人提出。 – (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ CGPoint mScrollPosition = [scrollView.panGestureRecognizer velocityInView:mCollectionView]; if (mScrollPosition.y > 0.0f){ NSLog(@"going down"); //Action One mYearHeaderTitle–; [self.mCollectionView reloadData]; } else if (mScrollPosition.y < 0.0f){ NSLog(@"going up"); //Action two mYearHeaderTitle++; [self.mCollectionView reloadData]; } }

下载文件时如何在UICollectionViewCell子类中更新progressBar

我要疯了,我试图更新UICollectionViewCelll当我下载一个文件,我已经尝试了一切,一切的一切,这是我最后一次尝试,我已经创build了一个UICollectionViewCell的子类,与xib文件连接: #import <UIKit/UIKit.h> @interface DocumentCell : UICollectionViewCell @property (weak, nonatomic) IBOutlet UIImageView *documentImage; @property (weak, nonatomic) IBOutlet UIProgressView *downloadBar; – (void)downloadDocumentWithUrl:(NSURLRequest *)requestUrl; @end – (void)downloadDocumentWithUrl:(NSURLRequest *)requestUrl { ….. AFDownloadRequestOperation *request = [[AFDownloadRequestOperation alloc] initWithRequest:requestUrl targetPath:zipDownloadPath shouldResume:YES]; [request setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Successfully downloaded file to %@", zipDownloadPath); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: […]

停止单个UICollectionView单元stream动到屏幕的中心

我想了解为什么集合视图保持中心只alignment集合中的最后一个单元格。 我创build了一个简单的基于stream布局的集合视图。 我使用的Autolayout标志 – 我不知道是造成这个问题。 每当我从收集视图中删除一个单元格 – 前几个似乎正常工作,滚到左侧。 但是,当我删除倒数第二个,然后突然最后一个单元格从左alignment更改为中心alignment。 有没有人有解释? 这似乎很奇怪。 我如何做到这一点,以便所有单元格将向左滚动并保持与左侧alignment。 编辑:这里是视图层次debugging: http : //imgur.com/a/NxidO 这是视图行为 我做了一个简单的github来演示它: https : //github.com/grantkemp/CollectionViewIssue 这里是代码: var dataforCV = ["short","longer phrase", "Super long Phrase"] override func viewDidLoad() { super.viewDidLoad() demoCollectionView.reloadData() let layout = UICollectionViewFlowLayout() // Bug Description – > UICollectionViewFlowLayoutAutomaticSize will center Align the layout if it has only […]

如何使UICollectionView细胞高度dynamic?

我有一个UIcollectionview 。 有一些CollectionView的单元格。 在那个CollectionviewCell里面有一个textview。 textview的内容是dynamic的。 所以细胞高度应该是dynamic的。 怎么做?

UICollectionView委托方法cellForItemAtIndexPath:indexPath不从sizeForItemAtIndexPath调用

当我打电话 [collectionView cellForItemAtIndexPath:indexPath:] 从内部 [collectionView:layout:sizeForItemAtIndexPath:] 那么委托方法不会被触发。 任何想法为什么不呢? 你可以在这里看到它。 – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CustomCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCell" forIndexPath:indexPath]; [cell configureWithData:self.data[indexPath.row]]; return cell; } – (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CustomCell * cell = (CustomCell *)[collectionView cellForItemAtIndexPath:indexPath]; return [cell prefferedSize]; } 我想要做的是要求单元格的大小。 我可以 CustomCell * cell = (CustomCell *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath]; 但是会触发一个永无止境的循环周期 […]

如何重新绘制不可见的UICollectionViewCell的旋转后准备好重用时发生?

如何重绘不可见的UICollectionViewCell准备好时重用发生? 我想到的一种方法是在Layout Cell prepareForReuse函数中使用代码,但是它的工作原理是非最优的,因为它会导致需要更多的重绘。 背景:在当前不可见的方向改变之后,需要为单元格触发drawRect ,但是popup来使用并且没有被重画,所以到目前为止,我只能看到prepareForReuse是合适的。 问题是我正在重新绘制所有的“重用”单元格,而我真的只想重绘那些最初popup在设备的前一个方向位置创build的单元格。 其他信息:所以目前我正在这样做: 在ViewController中: override func viewWillLayoutSubviews() { // Clear cached layout attributes (to ensure new positions are calculated) (self.cal.collectionViewLayout as! GCCalendarLayout).resetCache() self.cal.collectionViewLayout.invalidateLayout() // Trigger cells to redraw themselves (to get new widths etc) for cell in self.cal?.visibleCells() as! [GCCalendarCell] { cell.setNeedsDisplay() } // Not sure how to "setNeedsDisplay" on […]

强制触摸UI​​TableViewCell里面的UICollectionView

我有一个tableview,多个TableViewCells和每个TableViewCell,具有多个UICollectionViewItems的UICollectionView viewController。 每个collectionView项目都有一个标签和图像视图。 我试图让3D触摸工作,以便用户和偷看和popup的力量触及表格区域,不包含集合视图,预览和popup到一个视图控制器,然后能够做到与collectionView中的图像中的一个相同,但预览并popup到不同的视图控制器中。 我有第一个场景工作正常,桌面细胞在开始强制触摸和“偷看”时保持在屏幕上。 我坚持让这个在集合视图中工作,不pipe我做什么只有一个图像视图框架保持清晰的第一个tableview行,无论我真正按下哪一行。 代码如下: func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { //get the tableviewCell if let tableCellPath = tableView.indexPathForRow(at: location) { print("tableCellPath=", tableCellPath) if let tableCell = tableView.cellForRow(at: tableCellPath) as? VenueMainTableViewCell { //user tapped on a beer in the collectionview if let collectionView = tableCell.collectionView { let collectionPoint = […]

以编程方式创buildUICollectionViewCell,无需使用笔尖或故事板

有没有一种方法来创buildUICollectionViewCell而不使用cellForItemAtIndexPath方法中现有的单元格标识符和现有的nib文件?