将长按手势和拖动手势结合在一起
我现在正在改变我的观点
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveRight:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[bubbleView[rightCnt] addGestureRecognizer:panRecognizer];
[panRecognizer release];
,我想通过长按拖动来做同样的事情。
有什么想法吗?
I'm moving my views by
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveRight:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[bubbleView[rightCnt] addGestureRecognizer:panRecognizer];
[panRecognizer release];
Now , I want to do same thing by drag with long press.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
UILongPressGestureRecognizer
已经为您完成了您想要的操作。看一下UIGestureRecognizerState
属性。来自文档:因此,基本上在调用
UILongPressGestureRecognizer
选择器之后,您会监听 UIGestureRecognizerStateBegan、UIGestureRecognizerStateChanged、UIGestureRecognizerStateEnded。在UIGestureRecognizerStateChanged
期间不断更改视图框架。UILongPressGestureRecognizer
already does what you want for you. Take a look at theUIGestureRecognizerState
property. From the documentation:So essentially after your
UILongPressGestureRecognizer
selector is called you listen to UIGestureRecognizerStateBegan, UIGestureRecognizerStateChanged, UIGestureRecognizerStateEnded. Keep changing your views frame duringUIGestureRecognizerStateChanged
.在 Swift 中,这可以使用下面的代码来实现
In Swift this can be achieved using below code
您不需要声明 _priorPoint;
就我而言,我只希望视图水平移动,因此我只更改 x 坐标。
这是我的解决方案:
You do not need to declare _priorPoint;
In my case, i only want the view to move horizontally so i'm only changing the x coordinate.
Here is my solution:
感谢 Hari Kunwar 提供 Swift 代码,但 longPressAction 函数未正确定义。
这是一个改进版本:
Thanks to Hari Kunwar for the Swift code, but the longPressAction function is not correctly defined.
Here's an improved version: