I have a few UIButtons at the bottom of my app's main view. These buttons intermittently don't highlight when a user taps them but their target methods always get called. I've discovered it's Control Center's gesture recognizer getting in the way of UIButton's highlighting. If I move the containing view up toward the middle of the screen everything functions as designed.
The issue is reported here https://devforums.apple.com/message/865922
As a workaround I've tried setting the highlighted state by hand with the target method. This seems to have the same effect of allowing the UIButton to highlight normally.
Any ideas how to work around this without redesigning these controls to appear elsewhere in the app?
Perhaps I use a standard view and add all the methods for touch interaction by hand? How would I do that? Is it even worth exploring?
I've posted a fix for this issue that brings the highlight back described in this question. The highlight is fixed by subclassing UIButton and overriding pointInside: to catch touch events
I've found a pretty simple workaround for this. Using standard properties like .highlighted = YES and .selected = YES doesn't seem to work within that bottom band. Instead of setting the highlighted state, I just set the background image of the button to the highlighted state with an unperceived delay BEFORE we call the final method.
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton"] forState:UIControlStateNormal];
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton-highlighted"] forState:UIControlStateHighlighted];
[self.stopRecordingButton addTarget:self action:@selector(stopRecordingDelay) forControlEvents:UIControlEventTouchUpInside];
-(void)stopRecordingDelay
{
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton-highlighted"] forState:UIControlStateNormal];
[self performSelector:@selector(stopRecording) withObject:nil afterDelay:0.025f];
}
- (void)stopRecording
{
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton"] forState:UIControlStateNormal];
//Do real stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With