问题
I have a UIViewController let's call it MainViewController, a child controller instance (ChildViewController of type UITableViewController) is added to MainViewController the accessibility of the ChildViewController is set and voiceover works fine for the same.
MainViewController has a toolbar button, on tap a custom view will be displayed as shown below
//CustomView class
func show() {
UIView.animate(withDuration:0.5, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 5, options: .curveEaseInOut, animations: {
self.disabledLayer.backgroundColor = UIColor.init(white: 0, alpha: 0.55)
self.transform = .identity
}, completion: {
(value: Bool) in
self.accessibilityElements = [titleLabel, closeButton] // titleLabel, closeButton are added dynamically to the view and are of type UILabel and UIButton respectively
})
}
by doing this the voiceover never used to reach(read) the custom view elements. after some research added below line to MainViewController in toolbar button tap handler
UIAccessibility.post(notification: .screenChanged, argument: actionView)
after this the voiceover starts reading the elements in the Custom View and can be navigated through elements using left and right swap.
But the issue is when i tap on any of the element in the CustomView it is not selected and read, instead the elements of ChildViewController which is in the background is selected and read at that tap position.
On Swap, works as expected
Issue - when tapped on close button, the element in the childview controller which is in the background is selected
Note: the CustomView has a child view with semi transparent background Color
Thanks in advance
回答1:
The custom view is a modal view which is displayed on top of the current uiviewcontroller.
Have added below line to CustomView which solved the issue.
self.accessibilityViewIsModal = true
Here VoiceOver would ignore the elements within views that are siblings of the receiver.
Refer Apple's doc for more details
来源:https://stackoverflow.com/questions/57552123/ios-voiceover-for-custom-view-displayed-over-uiviewcontroller