ios - Implement button dragging with momentum? -
i've managed implement draggable button in objective-c iphone app using code shown @ link: http://www.cocoanetics.com/2010/11/draggable-buttons-labels/
i wondering if library exists implement dragging momentum? if user moved button , let go, continue move little while, depending on drag coefficient.
i searched library, googled "ios button momentum" came empty...
if have support ios 6
you can animate change button's center
when pan gesture ends:
if(pangesturerecognizer.state == uigesturerecognizerstatedended) { finalvelocty.x = velocity.x; finalyvelocity.y = velocity.y; nstimeinterval animationtime = 0.25; //adjust time needs [uiview animatewithduration:0.25 animations:^{ button.center = ... // calculate button's 'final' center (depending on velocity?) } completion:nil]; }
for ios 7 or newer
apple's introduced uikit dynamics framework (consisting of uidynamicanimator , uidynamicitembehavior subclasses) in ios 7. it's physics engine integrated uikit. can use achieve "momentum" effect.
an example may find useful: http://www.teehanlax.com/blog/introduction-to-uimotioneffect/
Comments
Post a Comment