I have a bunch of regular UIButtons, with a target when pressed. But I also want it to work when swiped, and activate touchesbegan or touchesmoved/touchesended. I need it because I want create something like a swipable word puzzle, which will also receive touchup presses. But the swipe series only works if the touches begins on self.view , but not on the button themselves. It will just be pressed and no touch events are registered.
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];
Can anyone help? I know that putting the UIButtons in the subview might be troublesome, but I really wish to do that to keep the elements in a structured way, and not everything is directly on self.view.
I tried to subclass the buttons but it didn’t help
Subclassing code:
- (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
}
Looks like touch are responding but when it gets to the rect of uibutton, they will be intercepted.