我有一堆普通的UIButtons,按下時有一個目標。但我也希望它在刷卡時工作,並激活touchesbegan或touchesmoved/touchesended。我需要它,因爲我想創建一個像滑動字詞拼圖的東西,它也會接受touchup印刷。但是滑動系列只有在觸摸開始於self.view時才起作用,但不在按鈕上。它將被按下並且沒有觸摸事件被註冊。UIButton not firing touchesbegan
UIButton* Butt = [UIButton buttonWithType:UIButtonTypeCustom];
Butt.frame= CGRectMake(0, -500, 63 , 63);
[Butt addTarget:self action:@selector(clickWord:)forControlEvents:UIControlEventTouchUpInside];
Butt.userInteractionEnabled= YES;
[aSubview addSubview:Butt];
任何人都可以幫忙嗎?我知道將UIButtons放在子視圖中可能會很麻煩,但我真的希望這樣做以保持結構化的元素,而不是所有的東西都直接在self.view上。
我試圖子類的按鈕,但它並沒有幫助
子類代碼:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self.nextResponder touchesBegan:touches withEvent:event];
// This is where the touch is passed on
}
- (void) toouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
[self.nextResponder touchesMoved:touches withEvent:event];
// This is where the touch is passed on
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self.nextResponder touchesEnded:touches withEvent:event];
// This is where the touch is passed on
}