ios - Strange behavior of UIScrollView with Constraints and RTL -
i have horizontal scroll view on add views dynamically. on ltr languages work fine, add views 1 after other left right. on rtl problem views added left of scroll instead of right in every other controller, really strange staff order of views added correctly, left of first view ordered right left outside of scroll view on -x.
here code when add new view:
tag* tag = [self.storyboard instantiateviewcontrollerwithidentifier:@"tag" ]; [_scroller addsubview:tag.view]; [tags addobject:tag]; tag* prev = nil (tag* tag in tags) { if (prev == nil) { [_scroller addconstraint:[nslayoutconstraint constraintwithitem:tag.view attribute:nslayoutattributeleading relatedby:nslayoutrelationequal toitem:_scroller attribute:nslayoutattributeleading multiplier:1.0f constant:0]]; } else { [_scroller addconstraints:[nslayoutconstraint constraintswithvisualformat:@"[prev]-10-[tag]" options:0 metrics:nil views:@{@"tag" : tag.view, @"prev" : prev.view}]]; } [_scroller addconstraint:[nslayoutconstraint constraintwithitem:tag.view attribute:nslayoutattributecentery relatedby:nslayoutrelationequal toitem:_scroller attribute:nslayoutattributecentery multiplier:1.0f constant:0]]; prev = tag; }
here image of how suppose work on ltr , rtl , how works
it sounds better approach might use uicollectionview
. if want start right side possibly this:
nsindexpath *lastindex = [nsindexpath indexpathforitem:data.count - 1 insection:0]; [self.collectionview scrolltoitematindexpath:lastindex atscrollposition:uicollectionviewscrollpositionright animated:no];
this way uicollectionviewflowlayout
can handle placement you.
Comments
Post a Comment