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.
You need to subclass UISegmentedControl then override didUpdateFocusInContext. In the "Custom Class" field in IB use the name of your custom class.
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.
Related
How does the UIActionSheet's hit detection work? When a user selects an option and then moves it's finger to another option, the other option is highlighted as seen in the GIF's below. The detection also knows when a user is scrolling.
So this is achieved by listening for multiple UIControlEvents. Chances are you're used to listening for touchUpInside as this is standard for UIButton behaviour. But there are plenty more besides that. A full list and documentation can be found here.
In your case, you want to listen to touchDragEnter and touchDownInside, making the callback from these invoke some code that changes the background colour of your button.
You should also listen for touchDragExit and touchUpInside to return the background colour to normal.
Additionally, you should run the action code in touchUpInside.
I hope this clears things up!
UIAlertController contains a stack of items in subview with type UIStackView, this stack view is placed on the view with type _UIInterfaceActionRepresentationsSequenceView that has three gesture recognizers with types:
• UIScrollViewDelayedTouchesBeganGestureRecognizer
• UIScrollViewPanGestureRecognizer
• _UIDragAutoScrollGestureRecognizer
You can inspect it with Xcode built-in tool: User Interface Inspector.
I think that custom handlers of these recognisers provide this drag-and-highlight function.
Internal logic of UIAlertController handle touches and hit test subview in stack and set highlighted boolean property to YES for item under user's finger and to NO for others.
enter image description here
I am making app like sudoku (9*9 boxes) but it has only binary choices (on/off) and using button gave me horrible results. Can anyone give me demo version of 9*9 (or 3*3) box where depending upon the tap location, that specific box gets toggled (on/off)
You could create a custom subclass of UIView that had an attached tap gesture recognizer and interpreted the tap location to figure out which cell is being tapped, but it would be a lot of work.
It would be better to have custom view that contains a grid of buttons and set up the button actions to do what you want.
You said "...using button gave me horrible results." Can you elaborate? That should be a good way to go, so any "horrible results" are likely the result of something you did wrong, rather than that being the wrong way to go.
I know that voiceover can a be bag of hurt when used with an UIStepper because the UIButtons that it contains can't be customised. However I use this control to change a value displayed on a label:
I don't want to insert a new control just for voiceover and subclassing a control like UIStepper doesn't seem a good solution. Any ideas to implement voiceover with this interface?
You could have a view which wraps your label(s) and stepper together and which deals with the accessibility. So, the subviews are all disabled for accessibility and the wrapper view presents the text in the labels, the current value of the stepper and provides / handles a swipe based interface to increment and decrement the stepper. So, overall, the wrapper view would work like a slider.
An interface implementing a stepper may be well vocalized and presented by VoiceOver using the adjustable values.
A complete explanation is detailed here including illustrations and code snippets (ObjC + swift).
I have developed an IOS 8 custom keyboard. I want to give it "undo" and "redo" functionality, like the default system keyboard. I have tried it in different ways but was unable to find a good solution.
We can interact with a Text Input Object textDocumentProxy with the methods
insertText
deleteBackward
documentContextAfterInput
ocumentContextBeforeInput
But I was unable to find any way of implementing "undo" and "redo" functionality.
I think we can NOT implement these function (undo,redo)
According to https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html
Because a custom keyboard can draw only within the primary view of its
UIInputViewController object, it cannot select text. Text selection is
under the control of the app that is using the keyboard. If that app
provides an editing menu interface (such as for Cut, Copy, and Paste),
the keyboard has no access to it. A custom keyboard cannot offer
inline autocorrection controls near the insertion point.
I think there are many case that content of textfield changed and you can not know when it changed, how it changed. If we can not know, we can not know to undo to where too. I think so.
I'm developing Custom keyboard extension like you and I have many problems. (eg: how can we know the current cursor to get current text selection...)
My question: Current text selection in CustomKeyBoardExtension (hope somebody know)
i am trying to implement accessibility option in my book reader app. I have a slider(similar to ibooks) which is used for navigating between pages. i have seen this question posted by another user and implemented the same code in my app. Right now my slider is responding when i'm tapping on it. The voiceover is also speaking the label i have given in the code. But, the problem is that, i am unable to change the slider value and navigate to another page.. I dont know if it is the problem with my code or is it that i do not know how to replicate the gesture to change the value of the slider... Any help in this regard will be appreciated.... Thanku
Does the slider work with VoiceOver turned off?
If so, try swiping vertically up or down (top to bottom of display) after selecting the slider element with VoiceOver enabled.
Is it a UISlider, or something of your own devising? UISlider needs an actual vertical swipe once selected, and moves a pretty significant amount as a result — not a good experience for going to the next page.
If it's your own custom control, be sure you set UIAccessibilityTraitAdjustable.