Friday, 15 April 2011

ios - How to make a view float over a scroll view using autolayout -



ios - How to make a view float over a scroll view using autolayout -

in ios 6.0 release notes there next statement:

note can create subview of scroll view appear float (not scroll) on other scrolling content creating constraints between view , view outside scroll view’s subtree, such scroll view’s superview.

anyone have ideas?

i did playing around , have working illustration of sorts.

the view not scroll, gets set @ top, height difference between scrollview hight , arbitrary value.

// in viewdidload uiiview *myview = [[uiview alloc] init]; [self.scrollview addsubview:myview]; myview.translatesautoresizingmaskintoconstraints = no; nslayoutconstraint *constraint = [nslayoutconstraint constraintwithitem:self.mapview attribute:nslayoutattributetop relatedby:(nslayoutrelationequal) toitem:self.containerview attribute:(nslayoutattributetop) multiplier:1.0 constant:0]; [self.view addconstraint:constraint]; // give view intrinsic size nsdictionary *dict = nsdictionaryofvariablebindings(myview); nsarray *constraints = [nslayoutconstraint constraintswithvisualformat:@"|[myview]|" options:(nslayoutformatalignallbaseline) metrics:nil views:dict]; [self.view addconstraints:constraints]; // in view did appear // calc height height of scroll view - needs work float height = -self.scrollview.frame.size.height + 250; nslayoutconstraint *constraint = [nslayoutconstraint constraintwithitem:self.mapview attribute:nslayoutattributeheight relatedby:(nslayoutrelationequal) toitem:self.containerview attribute:(nslayoutattributeheight) multiplier:1.0 constant:offset]; [self.view addconstraint:constraint];

ios ios6

No comments:

Post a Comment