Change order of read items with VoiceOver

后端 未结 8 1208
醉话见心
醉话见心 2020-12-07 17:31

I have a bunch of buttons on the screen which are positioned intuitively visually but are not read in an intuitive order by VoiceOver. This is because certain buttons like U

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 17:54

    I found a convenience way yesterday. Similar to @TejAces ' answer. Make a new swift file, then copy these things into it.

    import UIKit
    
    extension UIView {
        func updateOrder(_ direction: Bool = true) {
            var tempElements: [Any]? = [Any]()
            let views = (direction) ? subviews : subviews.reversed()
            for aView in views {
                tempElements?.append(aView)
            }
            accessibilityElements = tempElements
        }
    }
    
    class ReorderAccessibilityByStoryBoardView: UIView {
        override func didAddSubview(_ subview: UIView) {
            updateOrder()
            super.didAddSubview(subview)
        }
    }
    

    Set the UIView(contains views you want to reorder)'s class as ReorderAccessibilityByStoryBoardView. Then you can reorder them by reordering storyboard's view list.

    Because subview doesn't contain views in StackView/ScrollView, you need to make a independent class in this file. Such as the ReorderAccessibilityByStoryBoardStackView down below.

    class ReorderAccessibilityByStoryBoardStackView: UIStackView {
        override func didAddSubview(_ subview: UIView) {
            updateOrder(false)
            super.didAddSubview(subview)
        }
    }
    

    With these codes, you can also reorder view's added in code by adding them in a specific order.

提交回复
热议问题