ios - Set NSLayoutConstraint Constant in iOS7 -


ok, have super weird issue. have uiscrollview i'm using update position of second uiview. so, when scroll uiscrollview, uiview moves @ proportional slower speed. code pretty simple.

scroller.scrolled += delegate {   if (scroller.contentoffset.y <= 0) {     filterstop.constant = 0;   } else {      filterstop.constant = -(scroller.contentoffset.y / 2);   } } 

filterstop nslayoutconstraint. scroller uiscrollview.

the problem whenever set filterstop.constant value derived scroller.content.y, resets scroll.contentoffset 0 in ios7 only. code works fine in ios8+. i've tried dozen variations on this. if set filterstop.constant static number (ie: 123.5), works.

i've tried saving value variable , forcing type thinking maybe getting cast improperly. if trace out value, works. but, minute set filterstop.constant, resets scroller.constentoffset.y again. scroller , filters not related. not nested or associated each other in way. so, have no idea why setting constant on constraint on filters in way affect scroller.

anyone know happening here?

ok had seems resetting contentsize between calling viewwilllayoutsubviews , calling viewdidlayoutsubviews

contentsize set to: {width=320, height=3000} called viewwilllayoutsubviews contentsize set to: {width=320, height=3000} contentsize set to: {width=0, height=0} called viewdidlayoutsubviews 

i subclassed scrollview , forced contentsize stay same so:

public class customscroller : uiscrollview {     public customscroller ()     {         contentsize = new cgsize(320,3000);     }      public override cgsize contentsize {         {             return base.contentsize;//new cgsize(320,3000);         }         set {             base.contentsize = new cgsize(320,3000);              console.writeline ("contentsize set to: "+contentsize);         }     }      public override void layoutsubviews ()     {         console.writeline ("layoutsubviews: "+frame.y);         base.layoutsubviews ();     } } 

you have set contentsize when view loads rather in viewdidlayoutsubviews.

i have updated code here solution detailed above , here result. result

note changed scrolled code work original too.

this works in ios7 , ios8. hope helps!


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -