UIButton doesn’t show highlight on tap [iOS]
Hello iOS developers
Today we have a quick post for you about one issue we faced with a UIButton and the highlighted state. We experienced it on a real device while the simulator worked fine. When we touch the button, action method was called but there were no visible state change (the highlighted state).
Issue and investigation
- Initially we were trying to “hardcode” logic to change the background image of the button for the TouchDown and TouchUp events. Everything was OK but the TouchDown event fired only after (what!?) we released the button. Right after that fired the TouchUp event and the button returned to the normal state.
- Then we added a test button in the center of the screen and it worked fine. Tap begin -> TouchDown fired, tap release -> TouchUp fired.
- Then we moved the problematic button to the center of the screen and it worked fine as well. Ha! – the issue is with the button position.
- Some time later we understood that we have “tap conflict” with a standard “go back swipe” gesture (UINavigationController InteractivePopGestureRecognizer conflicts with the touch event of the button).
this.NavigationController.InteractivePopGestureRecognizer.CancelsTouchesInView = false; this.NavigationController.InteractivePopGestureRecognizer.DelaysTouchesBegan = false; this.NavigationController.InteractivePopGestureRecognizer.DelaysTouchesEnded = false;
These options disable delay of touch events and which will fire at the right time now. We faced with the issue during the “Taxi Gorod” app development where you can see it in action. We are using Xamarin to deliver our Xamarin.iOS and Xamarin.Android apps but basically you will face the same issues with native app development as well.
Your DreamTeam Mobile