Prevent UISegmentedControl segment selection on focus on tvOS

tvos side menu
tvos focus
uisegmentedcontrol state
uisegmentedcontrol tutorial
uisegmentedcontrol multiline text
uisegmentedcontrol subviews
tvml layout
tvos search

I'm working on a simple UI on a tvOS app and I'm facing a strange problem.

When a UISegmentedControl get focused you can move your focus around and it automatically changes the selected segment. But what I'm looking for is a way to limit the segment selection only when the user taps the segment, not when he focused it.

Any idea?

Thanks in advance.


You need to have your own internal variable for the selected segment and only change its value when the select button is pressed (which you can get using a gesture recognizer). When the segment loses focus (detectable in didUpdateFocus function) you assign the value of your internal variable to the selected index of the segment control.

tvOS UISegmentedControl events, When a UISegmentedControl get focused you can move your focus around and it automatically changes the selected segment. But what I'm looking for is a way  In a custom control, how do you implement a sticky focus selection as seen in UISegmentedControl, UITabBar, UITableView, or UICollectionView? By 'sticky selection' I mean automatically diverting fo


You need to subclass UISegmentedControl then override didUpdateFocusInContext. In the "Custom Class" field in IB use the name of your custom class.

Segmented Controls - Interface Elements - tvOS, When a segment becomes focused it fires the selection event and is intended assuming keyboardSegmentedControl is the segmented control, start by How do you keep a user from accidentally changing the selected segment when focus​  Working with tvOS Segmented Controls in Xamarin. 03/16/2017; 6 minutes to read; In this article. A Segmented Control provides a set of linear elements, each of which can contain an icon or text, and is used to provide a set of related choices to the user.


You can subclass UISegmentedControl and disable the behavior by defining:

@objc func _selectFocusedSegment(){
    print ("select focused segment")
}

Beware that this solution is a hack. As far as I know there is no good, clean way to accomplish what you want short of steering clear of UISegmentedControl.

Also know that when a UISegmentedControl 'changes focus' between segments, it does not actually change focus. So hooking into focus updates like Nostradamus is suggesting will not work. To the focus engine UISegmentedControl behaves like a single large focusable element, not like a group of focusable segments. You can see this for yourself by debug inspecting a UIFocusUpdateContext on focusing towards or away from a UISegmentedControl.

I stumbled onto _selectFocusedSegment by defining a UISegmentedControl subclass and debug logging the various NSObject.perform methods, among others. My intent was to reverse engineer how UISegmentedControl retains a sticky last focused item, which is quite difficult to do on Apple TV. I was not able to find out exactly how UISegmentedControl manages focus, but I was able to find the answer to your question along the way.

Working with tvOS Segmented Controls in Xamarin, Segments become selected when focus moves to them, not when they're clicked. Carefully Avoid mixing text and images in a segmented control. Although  I can only swipe right, all the way across the UISegmentedControls (selecting each segment unintentionally) before the focus ever moves to the bottom of the view. Maybe this is because in my UI, the only other enabled button is in the bottom-right corner while the focus is in the top-left corner.


[PDF] S13 tvOS, An individual Segment becomes selected when it is in-focus (not and you should avoid mixing icons and text in a single Segmented Control. A segment’s title clearly identifies the type of content to expect when the segment is selected. In general, titles should be nouns (such as Library or Playlists). Use title-style capitalization. Capitalize every word of a segment’s text except articles, coordinating conjunctions, and prepositions of four or fewer letters.


How to create a segmented control and read values from it, Design principles, focus & parallax, UI elements, loading Keep primary content away from the edges of the screen. • 90px left/right, 60px top/bottom Do not put focusable items next to segments as they become already selected when focus moves to UISegmentedControl, UISearchBar support focus by default. • Focus​  A focus item is something on screen that can receive focus. By default, UIKit allows UIButton, UITextField, UITableView, UICollectionView, UITextView, UISegmentedControl and UISearchBar as focusable items. A focus environment is simply an object that contains focusable items and/or other focus environments.


Mastering the tvOS Focus Engine, Segments can be text or pictures; anything else will silently fail. As an example, this creates a segmented control that works with a favoriteColor state property, and adds a text view below that shows whichever value was selected: Safari, App Store, watchOS, tvOS, Mac and macOS are trademarks of Apple  I'm programatically changing focus in a tvOS app in response to a UISwipeGestureRecognizer. This all works fine, except there the nice 'boop' sound that plays when changing focus normally doesn't p