Animating the drag drop example
Posted by Jacob von Eyben on April 9th, 2012
As an update to my original ios drag drop post I have added an animation to the snap back to original position.
The changes is made to the DragContext.m file where the snapToOrignalPostion is changed to look like the following:
- (void)snapToOriginalPosition { [UIView animateWithDuration:0.3 animations:^() { CGPoint originalPointInSuperView = [_draggedView.superview convertPoint:_originalPosition fromView:_originalView]; _draggedView.frame = CGRectMake(originalPointInSuperView.x, originalPointInSuperView.y, _draggedView.frame.size.width, _draggedView.frame.size.height); } completion:^(BOOL finished) { _draggedView.frame = CGRectMake(_originalPosition.x, _originalPosition.y, _draggedView.frame.size.width, _draggedView.frame.size.height); [_draggedView removeFromSuperview]; [_originalView addSubview:_draggedView]; }]; }
First we animate the dragged object back to the original position (in the super view containing all drag objects and drop areas). When the animation is completed, we change the superview.
April 9th, 2012 at 8:14 pm
[...] Animating the drag drop example [...]