ios - Autolayout Without UIScrollView -



ios - Autolayout Without UIScrollView -

i have been looking around solution unusual auto layout issue. trying set paging uiscrollview 5 pages. each page has own container, generic uiview. current setup looks this:

uiview *container = [[uiview alloc] init]; container.translatesautoresizingmaskintoconstraints = no; nslayoutconstraint *width =[nslayoutconstraint constraintwithitem:container attribute:nslayoutattributewidth relatedby:0 toitem:self.headlineview attribute:nslayoutattributewidth multiplier:1.0 constant:0]; nslayoutconstraint *height =[nslayoutconstraint constraintwithitem:container attribute:nslayoutattributeheight relatedby:0 toitem:self.headlineview attribute:nslayoutattributeheight multiplier:1.0 constant:0]; nslayoutconstraint *top = [nslayoutconstraint constraintwithitem:container attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.headlineview attribute:nslayoutattributetop multiplier:1.0f constant:0.f]; nslayoutconstraint *left = [nslayoutconstraint constraintwithitem:container attribute:nslayoutattributeleft relatedby:nslayoutrelationequal toitem:self.headlineview attribute:nslayoutattributeleft multiplier:index constant:self.headlineview.frame.size.width]; [self.headlineview addsubview:container]; [self.headlineview addconstraints:@[width, height, top, left]];

context: called within for-loop executes 5 times, variable index increments each time. working properly.

based on lastly constraint, thought give desired effect. multiplier each time (0-4) move left border on 1 unit of scroll view's frame.

the actual result quite strange. 5 of views located on sec page of scroll view, overlapping 1 another.

are multiplier , constant parameters not used thought are? messing here?

best guess view hasn't drawn frame of self.headlineview. if set nslog(cgstringfromrect(self.headlineview.frame)); before set constraints i'd bet it'll 0.

try calling:

[view setneedslayout]; [view layoufifneeded];

... before set constraints, or seek calling constraint method within of viewdidlayoutsubviews instead of (presuming viewdidload?).

ios objective-c uiscrollview autolayout nsautolayout

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -