2011-02-10 151 views
1

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

回答

0

我不想你可以添加一个UIPinchGestureRecognizer到按钮通常我们将它添加到视图的权利。我认为UIButton的行动就像IB中定义的“TouchUpInside”一样。

0

据我所知,你可以添加一个手势到UIButton

这里是一个小的代码给你一个总体思路:

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

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addGestureRecognizer:pinch]; 

我不认为你需要做的全部initWithTarget:self action:...但是这是我成功地做了视觉上的变化的唯一方式是由某种类型的UIGestures引起的。

如果按照你我的例子:@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 
}