我有一个 UICollectionView
我正在填充几个单元格和一个自定义流布局。这在纵向模式下效果很好。当我旋转到横向时,我遇到了无法在屏幕右侧向上/向下滑动的问题。似乎是对触摸没有反应的正确 w-h 像素。 Collection View 确实正确绘制了单元格,其他一切看起来都很正常。此外,如果我在工作区开始滑动并沿对角线进入无响应区域,则拖动继续起作用。
当设备旋转时,我会进行以下调用:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
_currentIndex = self.assetsCollectionView.contentOffset.y / self.assetsCollectionView.bounds.size.height;
[self.assetsCollectionView.collectionViewLayout invalidateLayout];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
float y = _currentIndex * self.assetsCollectionView.bounds.size.height;
[self.assetsCollectionView setContentOffset:CGPointMake(0, y) animated:NO];
}
这些对我来说看起来不错,当我将它们完全注释掉时,我会得到相同的行为。
其他细节: UICollectionView 是我的 View Controller 中唯一的 UI 组件,除了一个小的细节标签,我确信这不是问题。
我在 UICollectionViewFlowLayout 的两个子类之间切换,以便单元格可以扩展到全屏并返回,但是无论哪种布局,甚至在我换掉它们之前,我都遇到了同样的问题。另一个细节是全屏布局是 pageEnabled 而较小的布局不是。
包含的 UIViewController 位于 UITabController 内。
还有一点需要注意:我已经仔细检查了我的布局约束,以确保那里也没有有趣的事情。
有任何想法吗?
最佳答案
我有完全相同的问题。在花了一个晚上试图找出问题所在之后,我设法通过在 CollectionView View Controller 类的 viewDidLoad 方法中添加这两行来解决它。 (我不使用自动布局)
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
我希望这也能解决您的问题。
关于ios - UICollectionView 在横向模式下对右侧 w-h 像素滑动无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20363008/