简体   繁体   English

UIPanGestureRecognizer:手指下方的偏移视图

[英]UIPanGestureRecognizer: Offset view under finger

I have a scrollView with some UIViews as subviews that I drag around. 我有一个带有一些UIViews的scrollView作为拖动的子视图。 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]; 尝试下面的代码CGPoint touchPoint = [recognizer locationInView:self]; try changing touchPoint 尝试更改touchPoint

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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