【发布时间】:2012-11-09 12:22:19
【问题描述】:
我正在尝试处理 UICollectionViewController 中的界面方向更改。我想要实现的是,我希望在界面旋转后拥有 same contentOffset。意思是,应该根据边界变化的比例来改变它。
从纵向开始,内容偏移量为 {bounds.size.width * 2, 0} ...
... 应该导致横向内容偏移也与 {bounds.size.width * 2, 0} (反之亦然)。
计算新的偏移量不是问题,但不知道在哪里(或何时)设置它,以获得平滑的动画。我所做的是使willRotateToInterfaceOrientation:duration: 中的布局无效并重置didRotateFromInterfaceOrientation: 中的内容偏移量:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration;
{
self.scrollPositionBeforeRotation = CGPointMake(self.collectionView.contentOffset.x / self.collectionView.contentSize.width,
self.collectionView.contentOffset.y / self.collectionView.contentSize.height);
[self.collectionView.collectionViewLayout invalidateLayout];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
{
CGPoint newContentOffset = CGPointMake(self.scrollPositionBeforeRotation.x * self.collectionView.contentSize.width,
self.scrollPositionBeforeRotation.y * self.collectionView.contentSize.height);
[self.collectionView newContentOffset animated:YES];
}
这会改变旋转后的内容偏移量。
如何在旋转过程中设置它?我尝试在willAnimateRotationToInterfaceOrientation:duration: 中设置新的内容偏移量,但这会导致非常奇怪的行为。
可以在GitHub上的我的项目中找到一个示例。
【问题讨论】:
-
您找到解决方案了吗?
标签: ios objective-c cocoa-touch uiscrollview uicollectionview