UIPanGestureRecognizer在触摸时立即执行某些操作 [英] UIPanGestureRecognizer do something immediately when touched

查看:290
本文介绍了UIPanGestureRecognizer在触摸时立即执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ios的新手,所以如果我遗漏了一些明显的东西,我会提前道歉。

I am new to ios, so I apologize in advance if I am missing something obvious.

我正在制作一个拼图,我希望个别拼图可以触摸尺寸增加,放手减少。

I am creating a puzzle where I would like the individual puzzle pieces to increase in size on touch and decrease on letting go.

目前我有:

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
  if(recognizer.state == UIGestureRecognizerStateBegan)
  else if(recognizer.state == UIGestureRecognizerStateEnded)
}

当平底锅开始时(这也是状态开始时),拼图块会增加尺寸,当平底锅结束时(如预期的那样)尺寸会减小。一旦用户触摸了这件作品并且在拼图块移动之前,我希望尺寸增加。选择图块时可以在Words With Friends中看到。

The puzzle piece increases size when the pan begins (which is also when the statebegan) and decreases in size when the pan ends (as expected). I would like the size to increase once the user has touched the piece and before the puzzle piece moves. This is seen in Words With Friends when selecting a tile.

我试过了

-(IBAction)handleTap:(UITapGestureRecognizer *)recognizer{
  if(recognizer.state == UIGestureRecognizerStateBegan)
  else if(recognizer.state == UIGestureRecognizerStateEnded)
}

只有在手指抬起后才会增加拼图。

This will increase the puzzle piece only after the finger has lifted.

我的问题:

一旦手指触摸拼图块然后继续平移手势,是否有办法增加拼图块的大小。

Is there a way to increase the size of a puzzle piece once the finger has touched the puzzle piece and then continue with the pan gesture.

提前谢谢。

推荐答案

我需要做的这也是,杰克的建议对我来说非常合适。如果它有助于将来遇到这种情况的任何人,这里是我的 UIPanGestureRecognizer 的子类实现(标题保持不变):

I needed to do this too, and Jake's suggestion worked perfectly for me. In case it helps anyone who comes across this in the future, here is my subclass implementation of UIPanGestureRecognizer (the header remains unchanged):

#import "ImmediatePanGestureRecognizer.h"
#import <UIKit/UIGestureRecognizerSubclass.h>

@implementation ImmediatePanGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    self.state = UIGestureRecognizerStateBegan;
}

@end

这就是你所需要的 - 当你将手指放在视图上时会立即触发,只要你将手指向任何方向移动一个点就会立即更新,并提供常规 UIPanGestureRecognizer (例如 translationInView velocityInView )在常规触发之前,所有这些都不会破坏任何现有功能。

This is all you need—this will fire as soon as you put your finger down on the view, update as soon as you move your finger a single point in any direction, and provide the functionality of a regular UIPanGestureRecognizer (like translationInView and velocityInView) before a regular one would've fired, all without breaking any existing functionality.

这篇关于UIPanGestureRecognizer在触摸时立即执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆