在支持RTL语言的项目上的UICollectionView iOS 9问题 [英] UICollectionView iOS 9 issue on project with RTL languages support

查看:928
本文介绍了在支持RTL语言的项目上的UICollectionView iOS 9问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple使用RTL语言自动翻转界面的新功能似乎在使用 UICollectionView 时会出现问题。

It seems like Apple's new feature of auto-flip interface on RTL languages cause problems when using UICollectionView.

我在集合视图中使用了Trailing / Leading类型的约束,他们按照RTL语言切换了它们的值。

I used constraints of type Trailing/Leading for the collection view and they switched their values, as they should, on RTL language.

问题是实际呈现的数据是集合的数据源中的最后 indexPath ,但 UIScrollView.contentOffset.x 第一个单元格是0。

The problem is that the data actually presented is of the last indexPath in the collection's data source but the UIScrollView.contentOffset.x of the first cell is 0.

正确的行为可能是以下之一:

A proper behaviour would have been one of the following:


  1. 正确显示第一个 indexPath 并切换滚动方向(向右) - 最佳选项

  2. 不翻转UI /约束,以便显示所呈现的数据/ indexPath / scrollView.contentOffset.x - 选项禁用RTL支持。

  3. 显示最后一个indexPa的单元格和数据然后修复 scrollView.contentOffset.x 以表示最后一个单元格位置。

  1. Displaying the first indexPath correctly and switching the direction of the scroll (to the right) - Best option
  2. Not flipping the UI/Constraints so the presented-data / indexPath / scrollView.contentOffset.x will be synchronised - Option that disabling the RTL support.
  3. Presenting cell and data of the last indexPath but fixing the scrollView.contentOffset.x to represent the last cell position also.

我猜Apple可能会在将来的某个时候修复它,但同时我们必须使用诸如反转数组和/或滚动到最后一个对象的变通办法。

I guess Apple might fix it sometime in the future but meanwhile we'll have to use workarounds like reversing array and/or scrolling to the last object.

推荐答案

我遇到了类似的情况并找到了解决方案。如果您使用的是swift,请将以下代码段添加到项目中,并确保bounds.origin始终遵循集合视图的前沿。

I was in a similar situation and found a solution for this. If you are using swift, add the following snippet to your project, and it will make sure that the bounds.origin always follows leading edge of the collection view.

extension UICollectionViewFlowLayout {

    open override var flipsHorizontallyInOppositeLayoutDirection: Bool {
        return true
    }
}

如果您使用的是Objective-C,只需继承UICollectionViewLayout类,并覆盖flipsHorizo​​ntallyInOppositeLayoutDirection,并返回true。使用此子类作为集合视图的布局对象。

If you are using Objective-C, just subclass the UICollectionViewLayout class, and override flipsHorizontallyInOppositeLayoutDirection, and return true. Use this subclass as the layout object of your collection view.

这篇关于在支持RTL语言的项目上的UICollectionView iOS 9问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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