swift - UIView animation acting weird -


my view controller's view has child view -a "login" panel of sorts, 2 input text fields- placed @ center, autolayout constraints set in interface builder. view controller class has outlet set reference vertical constraint , manipulate @ run time.

on startup -viewdidlayoutsubviews()-, cache value of vertical constraint in property (constraintinitialvalue), calculate value hide panel beneath view's bounds (based on both panel's , view's sizes) , apply value immediately, hiding panel before user sees view. cache calculated "off-screen" value of constrain in property (constraintoffscreenvalue), later use (e.g., "hide" panel).

(i initial setup in viewdidlayoutsubviews() because first opportunity actual bounds of view controller's view.)

(for record, original constraint value 0.0: center y, no offset. and, iphone 6 , current size of panel, "offscreen value" -453.0.)

in background, authenticate user. if fails, animate login panel original position (the center of screen).

so far, good.

next, when user enters credentials , hits return key password (the last input field), perform local validation (e.g., strings not empty) , "dismiss" panel animating off-screen position. if following code:

uiview.animatewithduration(nstimeinterval(0.3),             delay:nstimeinterval(0.0),             options:uiviewanimationoptions.curveeaseout,             animations: { () -> void in                  self.panelverticalspaceconstraint.constant = self.constraintoffscreenvalue                 self.view.layoutifneeded()             },             completion: { (finished) -> void in              }         ) 

(viewdidlayoutsubviews() gets called several times during animation, second call onwards code returns right away. initial setup mentioned above not executed more once)

my panel moves upwards, , same ammount downwards, ending @ center of screen (instead, should disappear @ bottom).

if try changing animation duration 0.3 10.0 (to proper @ what's happening), instead panel "jumps" almost above upper margin of view, , animates center. is, if initial jump didn't happen, obtain desired result (move bottom of view).

any suggestions? in advance...

addendum: if, instead of trying animate panel downwards, set constraint off-screen value immediately, this:

self.panelverticalspaceconstraint.constant = self.constraintoffscreenvalue self.view.layoutifneeded() 

...it disappears, bounce center of view right away! did that animation come from? constraint somehow "resisting change"?

ok, found answer. weird quirk of fate, can find mistakes after posting question (curse me million times!).

it turns out another, separate animation being executed concurrently (and thus, interfering with) lower-the-panel-to-below-the-bottom-of-the-screen animation:

i happen have similar animation, adjust panel's postion when keyboard appears ("duck keyboard" animation), , down again when keyboard dismissed, on devices actual overlap occurs (i.e., smaller screens), checking keyboard's dimensions (passed along uikeyboardwillshownotification notification) against of main view , panel.

i had forgotten 1 because testing on iphone 6 simulator, screen size causes minimal (almost imperceptible, nevertheless present) keyboard overlap , hence panel adjustment animation. when tried code on iphone 6+ simulator (where keyboard-ducking animation skipped altogether because no overlapping occurs), problem disappeared , animations behaved expected.

this other restore-panel-after-ducking-the-keyboard animation no longer needed in code, because way dismiss keyboard when valid credentials have been entered, , autnentication begins (lowering panel way down, off-screen). panel reappears if entered credentials failed authenticated on server side.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -