I have subclassed UIButton in order to do some custom drawing with CoreGraphics in drawRect:
. In order to respond to touch events, I am adding these target/actions:
[self addTarget:self action:@selector(selectedButton:) forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragInside];
[self addTarget:self action:@selector(deSelectedButton:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchDragOutside | UIControlEventTouchUpOutside];
And an example implementation is this:
- (void)selectedButton:(id)sender {
self.isSelected = YES;
[self setNeedsDisplay];
}
This works pretty well. The only problem is that if I touch down/up really fast, the action is still processed, but the selected/deSelected methods get called so quickly that the background is never updated. But it works well if I press down for a little longer.
What am I missing here? How can I make my background update for the slightest of touches? I have tried delaying the deSelect call to update the layout, but it has no effect.