Tag: uitouch

通过兄弟子视图传播触摸事件?

我有一堆子视图,都有用户交互部分(子)和全屏幕。 问题是,如果我触及堆栈顶部的一个非交互式部分,那么它将不会在堆栈的其余部分传播该触摸。 我的设置: 查看A – 查看B(全屏容器,本身不具有交互性,但具有交互式子视图)—-查看B1(交互式)—-查看B2(交互式) – 查看C(与B相同)—-查看C1(交互式)—-查看C2(交互式) B和C都是全屏,但B1 / B2 / C1 / C2只是屏幕的一小部分。 [a addSubview:b]; [a addSubview:c]; 如果我触摸C1 / C2以外的任何东西,我想要触摸事件来检查它是否碰到了B(B1 / B2)中的任何地方,而是只返回到A,然后返回到A的父亲。 是否有可能做到这一点? 如果我在C上设置了userInteractionEnabled NO,但在C1 / C2上设置了YES,它也不会收到任何对内部的调用,尽pipe在这种情况下,B会按照预期得到触摸。 编辑:结束了手动遍历视图堆栈只检查某些子视图,而不是全部: – (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if (self != self.topCustomViewsContainer) { for (UIView *v in self.createdSubviews) { CGPoint newPoint = point; newPoint.x -= v.frame.origin.x; newPoint.y […]

时间戳和计算滑动的速度

嘿,我知道已经有几个关于这个的文章 – 但我仍然无法find一个适当的答案,我遇到的问题。 刚开始cocoa和iOS,我正在开发我的第一个iOS游戏。 在这个游戏中,我希望能够计算用户的滑动速度。 我毫不费力地find了滑动运动中连续触摸之间的距离,但是难以确定触摸之间所经过的时间 在touchesMoved:我做了当前的触摸计算,以及作为一个UITouch跟踪最近以前logging的触摸 在touchesEnded:我现在想要计算刷卡的速度,但是当我做这样的事情: double timeDelay = event.timestamp – self.previousTouch.timestamp; 这总是返回0。 但是,使用gcc我能够看到两个时间戳实际上是不一样的。 此外,在检查时,我看到这些事件的NSTimeInterval值在〜10 ^( – 300)的范围内。 这似乎很奇怪,因为NSTimeInterval应该报告几秒钟,因为系统启动不是? 我也试着跟踪上一次触摸的NSDate,并与[NSDate timeIntervalSinceNow]结合使用。 这产生了更奇怪的结果,每次返回大约6的值。 同样,由于timerIntervalSinceNow返回一个NSTimeInterval ,这个值非常奇怪。 什么是我不了解时间戳? 事件? 任何帮助,将不胜感激! 谢谢你的时间 一些支持代码: 在sampleController.h中: @property(nonatomic) UITouch* previousTouch @property(nonatomic) UITouch* currentTouch 在sampleController.m中: @synthesize previousTouch = _previousTouch, currentTouch = _currentTouch; … – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { self.currentTouch = […]

如何在UIPanGestureRecognizer方法中获取当前触点和上一个触点?

我是新来的iOS,我在我的项目中使用UIPanGestureRecognizer 。 我在拖动视图时需要获取当前触摸点和上一个触摸点。 我正在努力得到这两点。 如果我使用touchesBegan方法而不是使用UIPanGestureRecognizer ,我可以通过下面的代码得到这两点: – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ CGPoint touchPoint = [[touches anyObject] locationInView:self]; CGPoint previous=[[touches anyObject]previousLocationInView:self]; } 我需要在UIPanGestureRecognizer事件触发方法中获得这两点。 我怎样才能做到这一点? 请指导我。

UITouch触摸移动手指方向和速度

如何在touchmoved函数中获得手指移动的速度和方向? 我想获取手指速度和手指方向,并将其应用于UIView类的方向移动和animation速度。 我读了这个链接,但是我不明白答案,另外也没有解释我如何检测方向: UITouch移动速度检测 到目前为止,我试过这个代码: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *anyTouch = [touches anyObject]; CGPoint touchLocation = [anyTouch locationInView:self.view]; //NSLog(@"touch %f", touchLocation.x); player.center = touchLocation; [player setNeedsDisplay]; self.previousTimestamp = event.timestamp; } – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self.view]; CGPoint prevLocation = [touch previousLocationInView:self.view]; CGFloat distanceFromPrevious […]

你怎么知道触摸什么对象?

我知道这是一个非常常见的问题,但是每个网站上的所有答案都不起作用! 如果你仍然不知道我的意思,那么也许这行代码将帮助你理解。 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:self.view]; if (touch.view == nextbutton) [self performSelector:@selector(next)]; if (touch.view == prevbutton) [self performSelector:@selector(previous)]; if (touch.view == moreoptionsbutton) [self performSelector:@selector(moresettings)]; } nextbutton, prevbutton, and more optionsbutton当你触摸nextbutton, prevbutton, and more optionsbutton ( UIImageViews ,它什么也不做。 我也尝试使用isEqual:而不是== ,但是还没有解决。 有什么build议么?

开始触摸的次数不等于完成触摸的次数

我有以下代码用于testing目的: – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } – (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } – (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } – (void)customTouchHandler:(NSSet *)touches { for(UITouch* touch in touches){ if(touch.phase == UITouchPhaseBegan) touchesStarted++; if(touch.phase == UITouchPhaseEnded || touch.phase == […]

获取UITestureRecognizer的UITouch对象

有没有办法获得与手势相关联的UITouch对象? UIGestureRecognizer似乎没有任何方法。

UISystemGateGestureRecognizer和延迟接近屏幕底部的水龙头

iOS应用程序顶级UIView上安装的标准UISystemGestureGateGestureRecognizers是什么? 我的应用程序包含两个视图 – 一个填充屏幕的上半部分,另一个是自定义键盘,并填充下半部分。 我发现空格键上的水龙头并不总是工作,经过一些调查发现,最低20像素左右的水龙头事件的时间与其余部分不同。 对于大部分的观点来说,touchesBegan / Ended之间的时间间隔大约是100ms,而空格键是1-2ms。 (我的应用程序是一个模拟器,这是太快,它检测到按键)。 经过一些挖掘,我发现应用程序的主要UIView (即:我的主视图的UISystemGestureGateGestureRecognizer视图)有2个UISystemGestureGateGestureRecognizer的安装。 通过在ViewDidAppear删除它们, ViewDidAppear的底部不再受到影响。 (推测这些取消触摸按下事件到我的键盘,因此更快的时间)。 这些系统识别器至less在iOS 5至iOS 7以及iPad和iPhone上都有。 我以为他们可能是从顶部/底部刷卡有关,但这个function仍然适用于他们删除。 所以我有一个解决办法,但我想更多地了解这里发生了什么 – 特别是我可能会通过删除这些。

UIButton按住动作和释放动作

我想创build一个可以按下的UIButton,当它按下时,它会调用一次“hold down”操作。 当它被释放时,调用“暂停释放”动作。 此代码无法正常工作,因为触摸可以在button内移动,并且事件不会以正确的顺序触发 [button handleControlEvent:UIControlEventTouchDown withBlock:^{ [self performMomentaryAction:PXActionTypeTouchDown]; }]; [button handleControlEvent:UIControlEventTouchUpInside withBlock:^{ [self performMomentaryAction:PXActionTypeTouchUp]; }]; 句柄控制事件是基于UIButton +模块实现的

如何跟踪多个触摸

嘿,我有一个良好的代码在我的触动感动了@Sam_M给我。 我试图基本上跟踪移动时多个手指的位置。 像手指1在这里,手指2在那里。 因此,现在它将打印当前在视图和位置上的手指/触摸的数量,但是它不会分别跟踪两个单独的手指。 我环顾了仅有的3个其他问题,在计算器上。 但没有一个给了我一个很好的结果,我可以迅速实施。 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch: UITouch in event!.allTouches()! { for (index,touch) in touches.enumerate() { let ptTouch = touch.locationInNode(self.view) print("Finger \(index+1): x=\(pTouch.x) , y=\(pTouch.y)") } } } override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch: UITouch in event!.allTouches()! { for (index,touch) in touches.enumerate() […]