UICollectionView iOS 9 issue on project with RTL languages support

前端 未结 5 2107
礼貌的吻别
礼貌的吻别 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: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);
    }
    

提交回复
热议问题