这是一个非常直截了当的问题,但是我无法在SO上找到明确的答案(如果我错过了,请纠正我).
基本上,我的问题是:是否可以UICollectionView从右到左而不是从左到右对齐行内容?
在我的研究中,我看到了建议子类化的答案UICollectionViewFlowLayout,但我还没有找到一个为右对齐创建一个例子的例子.
我的目标是设置2个集合视图,如下所示:

任何帮助是极大的赞赏!
objective-c right-to-left ios uicollectionview uicollectionviewlayout
我希望有一个从右向左滚动的UICollectionView,即当它在加载后出现在屏幕上时,收集视图应该首先显示最右边的单元格/项目,然后在左边添加其余的.我已经尝试了这里提供的解决方法,但是如果我打电话给viewWillAppear:我,我得到:
*** Assertion failure in -[UICollectionViewData layoutAttributesForItemAtIndexPath:], /SourceCache/UIKit/UIKit-2372/UICollectionViewData.m:485
Run Code Online (Sandbox Code Playgroud)
如果我滚动到它中的最后一项viewDidAppear:工作正常,除了现在用户首先看到左项,然后滚动到最后一项.使用也试过contentOffset在UICollectionView财产(因为它的UIScrollView的一个子类),但这个参数也只设置在某个时候之间viewWillAppear:和viewDidAppear:
任何替代品?我想我可以尝试子类化UICollectionViewFlowLayout并从右到左布局单元格,但我有点急于进入那个领域.
这就是我做的:
- (void)_scrollToTheRight
{
NSIndexPath *lastIndexPath = [self.fetchedResultsController indexPathForObject:self.fetchedResultsController.fetchedObjects.lastObject];
if (lastIndexPath)
{
[self.collectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionRight animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
每个值是:
lastIndexPath
(NSIndexPath *) $0 = 0x1f1754a0 <NSIndexPath 0x1f1754a0> 2 indexes [0, 21]
(NSInteger)[self.fetchedResultsController.fetchedObjects count]
(NSInteger) $3 = 22 [no Objective-C description available]
(NSInteger)[self.collectionView numberOfItemsInSection:0]
(NSInteger) $2 = 22 [no Objective-C description available]
Run Code Online (Sandbox Code Playgroud)
最后一点:集合视图控制器是从UIPageViewController放在屏幕上的视图控制器的容器视图(iOS 6故事板中的新内容)加载的.
谢谢.
编辑1:
所以我认为问题是使用我的故事板布局(UICollectionViewController …