Tag: uigesturerecognizer

在数组上映射一个void(非返回函数)

标题是不言而喻的,是否有任何映射的方式,例如,通过UIGestureRecognizers数组addGestureRecognizer 。 我一直在摆弄各种各样的 recognizers.map(MyWebOutlet.addGestureRecognizer) 但由于内置映射必须返回另一个数组需要返回某种值的函数。 我应该在另一个返回函数中包装addGestureRecognizer还是另一个更聪明的方法?

如何添加触摸手势映射,但忽略引脚和注释触摸?

我有一个使用MKCircle s来显示某些用户操作的半径信息的mapview。 我想要做的就是允许用户在触摸地图时closuresMKCircle 。 不过,我希望MKCircle不要解雇,如果用户触摸任何其他针或MKCircle本身。 有任何想法吗? 这里是我当前的代码,当地图的任何部分被触摸时,它将closuresMKCircle : UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deactivateAllRadars)]; [tap setCancelsTouchesInView:NO]; [_mapView addGestureRecognizer:tap];

在SKScene中的UIPanGestureRecognizer

我一直在使用UIGestureRecognizers和SKScene/SKNode's新SKScene/SKNode's进行SpriteKit 。 我有一个问题,我已经接近修复它,但我对一件事感到困惑。 基本上,我有一个平移手势识别器,允许用户在屏幕上拖动一个精灵。 我遇到的唯一问题是,只需轻轻点击一下,即可初始化平移手势,然后只有第二次点击才能正常工作。 我在想,这是因为我的平移手势是在touchesBegan初始化的。 但是,我不知道在SKScene的initWithSize方法中初始化它之后,还有什么地方停止了手势识别器的实际工作。 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (!self.pan) { self.pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(dragPlayer:)]; self.pan.minimumNumberOfTouches = 1; self.pan.delegate = self; [self.view addGestureRecognizer:self.pan]; } } -(void)dragPlayer: (UIPanGestureRecognizer *)gesture { CGPoint trans = [gesture translationInView:self.view]; SKAction *moveAction = [SKAction moveByX:trans.xy:-trans.y duration:0]; [self.player runAction:move]; [gesture setTranslation:CGPointMake(0, 0) inView:self.view]; }

向前移动到一个UIScrollView

我有两个视图控制器。 视图控制器A具有UIScrollView并呈现视图控制器B.该呈现是交互式的并由scrollView.contentOffset控制。 我想集成一个交互式的解雇过渡:当平移时,ViewController B应该被交互式地解雇。 交互式解散转换也应该控制ViewController的scrollView。 我第一次尝试使用UIPanGestureRecognizer并根据平移距离设置scrollView.contentOffset 。 这工作,但是当平移手势结束时,scrollView偏移量必须被animation到结束位置。 使用-[UIScrollView setContentOffset:animated:不是一个好的解决scheme,因为它使用线性animation,不考虑当前的摇摄速度,并且不会很好地减速。 所以我认为应该有可能从我的平移手势识别器提供触摸事件到滚动视图。 这应该会给我们所有漂亮的滚动视图animation行为。 我尝试在我的UIPanGestureRecognizer子类中重写-touchesBegan/Moved/Ended/Cancelled withEvent:方法,如下所示: – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [scrollView touchesBegan:touches withEvent:event]; [scrollView.panGestureRecognizer touchesBegan:touches withEvent:event]; [super touchesBegan:touches withEvent:event]; } 但显然有些东西阻止了滚动视图进入tracking模式。 (它确实去dragging = YES但这是关于它。)我validation了scrollView是userInteractionEnabled ,不隐藏并添加到视图层次结构。 那么如何将我的触摸事件转发给UIScrollView呢?

为什么在我的textField清除button上调用UIGestureRecognizer?

我有一个添加了手势识别器的UITableView: UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)]; [myTableView addGestureRecognizer:gestureRecognizer]; gestureRecognizer.cancelsTouchesInView = NO; …一切工作正常时,在桌面上点击键盘解雇。 我的问题是,我的hideKeyboard方法也调用时点击我的UITextField上的“清除”button。 很奇怪。 commentTextField = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 310, 35)]; commentTextField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter; commentTextField.borderStyle = UITextBorderStyleRoundedRect; commentTextField.textColor = [UIColor blackColor]; //text color commentTextField.font = [UIFont fontWithName:@"Helvetica" size:14.0]; //font size commentTextField.placeholder = @"Enter a comment…"; //place holder commentTextField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto […]

用Swift和Xcode 6inheritanceUIGestureRecognizer – 如何导入UIGestureRecognizerSubclass.h?

除非您按照此处所述导入UIGestureRecognizerSubclass.h ,否则self.state在子类中写入self.state 。 在Swift环境中,我很困惑如何导入它。 我尝试import UIGestureRecognizerSubclass.h ,没有.h ,但我仍然无法写入self.state 。 我将如何做到这一点?

模拟UIScrollView减速

我有一个UIPanGestureRecognize ,我用它来改变视图的框架。 有一种方法来模拟手势的状态是UIGestureRecognizerStateEnded UIScrollView或UITableView的减速? 这是我现在的代码: if (panGesture.state == UIGestureRecognizerStateEnded) { [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ self.view.frame = CGRectMake(182, 0, self.view.frame.size.width, self.view.frame.size.height); } completion:^(BOOL finished) { if (finished) { //Do something } }]; } 但这不是一个光滑的滚动。 我想要一些减速的东西,直到它停止到我设定的点。 谢谢

拖动+旋转使用UIPanGestureRecognizer触摸下车轨道

我正在使用UIPanGestureRecognizer进行拖动和旋转计算。 旋转angular度是正确的,拖动位置几乎是正确的。 问题是,当你走在箱子的中心需要根据angular度进行调整,我不知道如何。 我已经包含了旋转过程中180度旋转的图像,但手指在哪里。 我只是不知道如何调整,使块适当地留在你的手指。 inheritance人一个video只是为了澄清,因为这是奇怪的行为。 http://tinypic.com/r/mhx6a1/5 编辑:这是一个真实的世界video应该发生什么。 问题是,在iPadvideo中,您的手指正在移动,在真实世界的任何地方,您的手指会粘在物品移动的特定位置。 math需要的是调整你的触摸位置的angular度与实际中心的差异。 我只是无法弄清楚math。 http://tinypic.com/r/4vptnk/5 非常感谢! – (void)handlePan:(UIPanGestureRecognizer *)gesture { if (gesture.state == UIGestureRecognizerStateBegan) { // set original center so we know where to put it back if we have to. originalCenter = dragView.center; } else if (gesture.state == UIGestureRecognizerStateChanged) { [dragView setCenter:CGPointMake( originalCenter.x + [gesture translationInView:self.view].x , […]

在长按识别器结束之后,wkwebview在调用正在导航行为

我试图覆盖原来的wkwebview操作… 首先,我通过webView.evaluateJavaScript webView.evaluateJavaScript("document.body.style.webkitTouchCallout='none';", completionHandler: nil)禁用了原始的wkactionsheet 然后我初始化一个长按手势识别器(它完美的工作),我创build了我自己的操作表。 我用decidePolicyForNavigationAction来获取点击链接的url: func onLongPress(gestureRecognizer:UIGestureRecognizer){ if gestureRecognizer.state == UIGestureRecognizerState.Began { longPressSwitch = true } } func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) { if(navigationAction.navigationType == .LinkActivated) { longPressAcUrl = navigationAction.request.URL!.absoluteString if(longPressSwitch == true) { let ac = actionMenu(self) self.presentViewController(ac, animated: true) { } decisionHandler(.Cancel) longPressSwitch = false } […]

和UIGestureRecognizer一起听UITouch事件

我正在创build一个自定义的UIView并添加一个UITapGestureRecognizer。 我有一个点击手势的处理程序。 但同时我想让我的UIView听touchesBegan&touchesEnded方法。 我已经实现了gestureRecognizer:shouldReceiveTouch:方法,但touchesBegan / touchesEnded方法不会被调用。 任何线索为什么? 在我的自定义UIView – (BOOL)gestureRecognizer:(UIGestureRecognizer *)iGestureRecognizer shouldReceiveTouch:(UITouch *)iTouch { return YES; } 我的视图控制器里面 MyCustomView aCustomView = [[[MyCustomView alloc] init] autorelease]; UIGestureRecognizer *myGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]; [aCustomView addGestureRecognizer:myGestureRecognizer]; [myGestureRecognizer release];