简体   繁体   中英

UIPanGestureRecognizer: Offset view under finger

I have a scrollView with some UIViews as subviews that I drag around. The problem is that the subviews is rather small, and when dragging them, you can't see them because the finger is in the way.

How do I offset the view a little bit upwards while dragging?

Thanks

if (recognizer.state == UIGestureRecognizerStateChanged)
{
    CGPoint translation = [recognizer translationInView:self];
    draggingView.center = CGPointMake(draggingView.center.x + translation.x,
                                      draggingView.center.y + translation.y);

    [recognizer setTranslation:CGPointZero inView:self];
}

Try following code CGPoint touchPoint = [recognizer locationInView:self]; try changing touchPoint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM