Ios 向按钮添加手势

Ios 向按钮添加手势,ios,uibutton,uigesturerecognizer,Ios,Uibutton,Uigesturerecognizer,我在IB中创建了许多按钮,并成功地将它们链接到操作。但是如果按钮被捏住,我想让另一个动作发生。我可能错过了一些基本的东西,但我似乎无法找到如何将UIPinchGestureRecognitor添加到按钮中 我不知道你可以在按钮上添加UIPinchGestureRecognitor,通常我们会将其添加到视图右侧。我认为对于UIButton,可用的操作就像IB中定义的“触碰内部”一样。据我所知,您可以向UIButton添加手势 下面是一小段代码,让您大致了解: UIPinchGestureRecog

我在IB中创建了许多按钮,并成功地将它们链接到操作。但是如果按钮被捏住,我想让另一个动作发生。我可能错过了一些基本的东西,但我似乎无法找到如何将UIPinchGestureRecognitor添加到按钮中

我不知道你可以在按钮上添加UIPinchGestureRecognitor,通常我们会将其添加到视图右侧。我认为对于UIButton,可用的操作就像IB中定义的“触碰内部”一样。

据我所知,您可以向
UIButton
添加手势

下面是一小段代码,让您大致了解:

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(someAction:)];

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addGestureRecognizer:pinch];
我认为您不必使用target:self action:…完成整个
init,但这是我成功完成由某种类型的
ui手势引起的视觉变化的唯一方法

如果您遵循我的示例:
@selector(someAction:)]您将按如下方式声明该方法:

-(void)someAction:(UIPinchGestureRecognizer *)sender
{
     //do what ever changes you want the gesture to cause here.
     //e.g. change the button size, color, shape
}