gpt4 book ai didi

iphone - 将长按手势和拖动手势结合在一起

转载 作者:IT老高 更新时间:2023-10-28 11:42:19 25 4
gpt4 key购买 nike

我正在移动我的观点

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveRight:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[bubbleView[rightCnt] addGestureRecognizer:panRecognizer];
[panRecognizer release];

现在,我想通过长按拖动来做同样的事情。

有什么想法吗?

最佳答案

UILongPressGestureRecognizer 已经为您做了您想要的。查看 UIGestureRecognizerState 属性。来自 documentation :

Long-press gestures are continuous. The gesture begins (UIGestureRecognizerStateBegan) when the number of allowable fingers (numberOfTouchesRequired) have been pressed for the specified period (minimumPressDuration) and the touches do not move beyond the allowable range of movement (allowableMovement). The gesture recognizer transitions to the Change state whenever a finger moves, and it ends (UIGestureRecognizerStateEnded) when any of the fingers are lifted.

所以基本上在您的 UILongPressGestureRecognizer 选择器被调用之后,您将聆听 UIGestureRecognizerStateBegan、UIGestureRecognizerStateChanged、UIGestureRecognizerStateEnded。在 UIGestureRecognizerStateChanged 期间不断更改您的 View 框架。

- (void)moveRight:(UILongPressGestureRecognizer *)gesture
{
if(gesture.state == UIGestureRecognizerStateBegan)
{
//if needed do some initial setup or init of views here
}
else if(gesture.state == UIGestureRecognizerStateChanged)
{
//move your views here.
[yourView setFrame:];
}
else if(gesture.state == UIGestureRecognizerStateEnded)
{
//else do cleanup
}
}

关于iphone - 将长按手势和拖动手势结合在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9272333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com