您應該使用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