UICollectionView iOS 9 issue on project with RTL languages support

前端 未结 5 2104
礼貌的吻别
礼貌的吻别 2020-12-14 00:49

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

I used constraints of type Traili

相关标签:
5条回答
  • 2020-12-14 01:22

    There is one common solution for that problem that works for me, follow below steps to overcome that problem,

    • Give the auto layout constraint as per your requirement and then from attribute inspector change the semantic control property of the collection view to Force right-to-left from the storyboard.

    • Then open storyboard as source code and find for the “leading” attributes of your relevant collection view and replace that with the “left” and same for the “trailing” replace that with the “right”. Now you almost done.

    • now that will give you result as per your requirement.
    0 讨论(0)
  • 2020-12-14 01:26

    I am late but if you don't want to create an extension because it will affect all the collection View in our app. Simply create your own custom class ie.

    class customLayoutForLocalization : UICollectionViewFlowLayout{
    open override var flipsHorizontallyInOppositeLayoutDirection: Bool {
        return true
    } }
    

    and is it

    0 讨论(0)
  • 2020-12-14 01:28

    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
        }
    }
    

    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.

    0 讨论(0)
  • 2020-12-14 01:32

    not pretty though simple math does the trick. (for horizontal collectionview)

    - (void)switchSemanticDirection:(UISwitch*)sender {
        //TEST switch the semantic direction between LTR and RTL.
        if (sender.isOn) {
            UIView.appearance.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
        } else {
            UIView.appearance.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
        }
    
        [self.myContent removeFromSuperview];
        [self.view addSubview:self.myContent];
        
        //reload your collection view to apply RTL setting programmatically
        [self.list reloadData];
        //position your content into the right offset after flipped RTL
        self.list.contentOffset = CGPointMake(self.list.contentSize.width - self.list.contentOffset.x - self.list.bounds.size.width, 
        self.list.contentOffset.y);
    }
    
    0 讨论(0)
  • 2020-12-14 01:42
    import UIKit
    
    extension UICollectionViewFlowLayout {
    
        open override var flipsHorizontallyInOppositeLayoutDirection: Bool {
            return UIApplication.shared.userInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.rightToLeft
        }
    
    0 讨论(0)
提交回复
热议问题