I\'m writing an app for tvOS - and it all works until I put a UIButton on the screen. The problem, when buttons are added, is that touchesBegan and touchesMoved stop workin
According to this answer, the button becomes a focused view and it's getting all the touches. You have to make your view (in which you implement touchesBegan
and touchesMoved
) focusable.
If the focus engine is used (for instance when you have a UITabbarController
or any UIButton
on the screen) the touch events such as touchesBegan: withEvent:
are indeed no longer called. If you really need them you must first make your view focusable by overriding its readonly property canBecomeFocused
:
- (BOOL)canBecomeFocused {
return YES;
}
Now the focus can be moved to your view and touch events will be triggered as long as it is in focus. However focus may be immediately lost again as it moves along to other focusable items on the screen.
To prevent this, implement on your view:
- (BOOL)shouldUpdateFocusInContext:(UIFocusUpdateContext *)context {
return NO;
}
Now your view can no longer lose its focus. This also means the user can no longer access other focusable items on the screen, so you may need implement logic that allows the user to leave again, for instance a button press.