iOS Touch, Gestures, Animation

亡梦爱人 提交于 2019-12-04 20:17:11

Why don't you consider using UIPanGestureRecognizer. You can use the translationInView: to move the box as moves the finger across. And when the gesture's state is UIGestureRecognizerStateEnded, you could use velocityInView: to get the desired follow up effect.

if (recognizer.state == UIGestureRecognizerStateEnded) {

    CGPoint velocityPoint = [recognizer velocityInView:yourView];

    [UIView setAnimationDelegate:self];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];



    [yourView setCenter:CGPointMake(yourView.center.x + (velocityPoint.x/4), yourView.center.y + (velocityPoint.y/4))];

    [recognizer setTranslation:CGPointZero inView:yourView];


   [UIView commitAnimations];

}

Hope this will help someone :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!