您应该使用tapGesture识别器用于获取点击事件,如低于该按钮 在viewDidLoad
。
- (void)viewDidLoad
{
UITapGestureRecognizer *btnTapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
btnTapped.numberOfTapsRequired = 1;
btnTapped.delegate = self;
[myBtn addGestureRecognizer:btnTapped];//here your button on which you want to add sopme gesture event.
[btnTapped release];
[super viewDidLoad];
}
这就是你的动画按钮使用的代码,因为它是。
[UIView animateWithDuration:3
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
myBtn.frame=CGRectMake(0, 100, myBtn.frame.size.width, myBtn.frame.size.height);
}
completion:^(BOOL finished) {NSLog(@"Animation Completed!");];
下面是允许同时识别委托方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
here Above methods Returning YES is guaranteed to allow simultaneous recognition. returning NO is not guaranteed to prevent simultaneous recognition, as the other gesture's delegate may return YES
- (void)tapAction:(UITapGestureRecognizer*)gesture
{
//do here which you want on tapping the Button..
}
编辑:如果你想找到的触摸手势,你应该使用UILongPressGestureRecognizer代替UITapGestureRecognizer并设置时间。
我希望它可以帮助你。
我想动画14个按钮,所以你认为这种方式对我来说很简单。在某种程度上,它应该看起来像一列火车。 – Rais
很抱歉,但我认为你必须! – Mutawe
这似乎是一个肯定的地狱。 – Eiko