ios - Programatic NSLayoutConstraint animation issues -


so trying animate layout constraints , having miserable luck, dont see , error message saying how can't simultaneously satisfy constrains etc.

i using class called pullableview animation using old style [uiview commitanimation] subclassed , added in code believe animating constraints...no such luck , attempting animate or of proving difficult "unable simultaneously satisfy constraints".. problem new constraint business not know start.

here error other 1 pretty same centery.

"<nslayoutconstraint:0x7c8a3a0 styledpullableview:0x905a9b0.centerx == uiview:0x9054680.centerx>", "<nslayoutconstraint:0x7c6b480 styledpullableview:0x905a9b0.centerx == uiview:0x9054680.centerx + 128>"

i of course [pullrightview settranslatesautoresizingmaskintoconstraints:no]; before calling this

any appreciated.

- (void)setopenedforconstraints:(bool)op animated:(bool)anim {     opened = op;      if (anim)     {                 nslayoutconstraint *constraintx = [nslayoutconstraint constraintwithitem:self                                                                                attribute:nslayoutattributecenterx                                                                                relatedby:nslayoutrelationequal                                                                                   toitem:_parentview                                                                                attribute:nslayoutattributecenterx                                                                               multiplier:1                                                                                 constant:0];          nslayoutconstraint *constrainty = [nslayoutconstraint constraintwithitem:self                                                                                attribute:nslayoutattributecentery                                                                                relatedby:nslayoutrelationequal                                                                                   toitem:_parentview                                                                                attribute:nslayoutattributecentery                                                                               multiplier:1                                                                                 constant:0];          [_parentview addconstraint:constraintx];         [_parentview addconstraint:constrainty];          constraintx.constant = opened ? self.openedcenter.x : self.closedcenter.x;         constrainty.constant = opened ? self.openedcenter.y : self.closedcenter.y;     }      if (anim)     {          // duration of animation, no further interaction view permitted         dragrecognizer.enabled = no;         taprecognizer.enabled = no;          //[uiview commitanimations];          [uiview animatewithduration:animationduration                          animations:^          {              [self layoutifneeded];          }];      }     else     {          if ([delegate respondstoselector:@selector(pullableview:didchangestate:)])         {             [delegate pullableview:self didchangestate:opened];         }     } } 

a couple of thoughts:

  1. you're creating new constraints here. adjust constant of existing constraint. or, if necessary, remove old constraint, , add new one.

  2. when changing existing constraint, there 2 approaches. 1 iterate through view's constraints, finding 1 in question, , adjusting constant that. other approach (and far easier when view 1 added in interface builder) create iboutlet constraint right in interface builder. can animate that.

    • this answer, while focusing on problem, illustrates process of creating iboutlet constraint , animating changing of value.

    • if have iterate through constraints looking constraints (e.g. picking out 1 constraint out of whole collection may have created visual format language, example), replaceleadingandtopwithcenterconstraints illustrated in this answer might helpful example of how find constraint on existing view. particular example removing constraint , adding new one, could, easily, once find existing constraint, adjust constant.


i'm not entirely sure of ux you're going for, let's have panel want slide off left of screen:

  1. the first issue constraints have defined: in example, i'd have 4 constraints defined, 3 superview (namely top, bottom, , left, not right) , width constraint. , if you're doing in ib, can finicky (e.g. cannot remove right constraint until add width constraint). make sure constraints defined, minimally so.

  2. then can animate sliding of panel off screen changing constant of left constraint:

    - (ibaction)touchupinsidebutton:(id)sender {     self.offscreen = !self.offscreen;      [uiview animatewithduration:0.5                      animations:^{                          self.panelleftconstraint.constant = ([self isoffscreen] ? -khowmuchtoslideofftoleft : 0.0);                          [self.view layoutifneeded];                      }]; } 
  3. you can see why important make sure there no right constraint defined. because if adjusted left constraint while had width constraint and right constraint defined, become unsatisfiable. making sure constraints minimally defined (though unambiguously defined) @ start, can change left constraint , view animates wanted to.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -