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

查看:15
本文介绍了支持 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.

问题是实际呈现的数据是集合数据源中last indexPathUIScrollView.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. 显示最后一个 indexPath 的单元格和数据,但修复 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天全站免登陆