gpt4 book ai didi

ios - UIPanGestureRecognizer:在滑动结束时检测触摸位置

转载 作者:行者123 更新时间:2023-12-01 17:30:12 25 4
gpt4 key购买 nike

我在touchesEnded方法中调用了一个名为addProjectile的方法。 addProjectile接收touchesEnded方法接收的触摸的NSSet。为简单起见,我仅将相关代码发布到我的问题中。因此,请明确说明:

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self addProjectile:touches]; }
-(void) addProjectile:(NSSet *)touches {//do stuff }

我想在名为swipeRight的UIPanGestureRecognizer方法的末尾调用addProjectile,并发送正确的触摸NSSet。
-(void)swipedRight:(UIPanGestureRecognizer *)recognizer {
CGPoint panned=[recognizer translationInView:self.view];
if(panned.x>50){//do stuff }
else {
NSSet *touches; <-- this is what I need to get
[self addProjectile:touches];

所以我的问题是,如何在swipedRight的末尾获得正确的NSSet触摸(这是用户抬起手指的地方):正确执行addProjectile方法。

最佳答案

看看UIGestureRecognizerState。那就是你所需要的。

示例代码(这里假设,您只需要在用户完成平移即举起手指时才需要触摸点):

-(void)swipedRight:(UIPanGestureRecognizer *)panGesture {

if ([panGesture state] == UIGestureRecognizerStateEnded) {

//User touch has ended

CGPoint touchUpPoint = [panGesture translationInView:self.view]; // or `locationInView:`

NSLog(@"__TOUCH_END_POINT__ = %@", NSStringFromCGPoint(touchUpPoint));
}
}

关于ios - UIPanGestureRecognizer:在滑动结束时检测触摸位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27879308/

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