iOS change accessibility focus.

前端 未结 3 1309
挽巷
挽巷 2021-01-03 17:40

is there a way to set the accessibility focus programatically (App Store-safe)? Any help will be greatly appreciated.

3条回答
  •  感动是毒
    2021-01-03 18:43

    extension UIAccessibility {
        static func setFocusTo(_ object: Any?) {
            if UIAccessibility.isVoiceOverRunning {
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
                    UIAccessibility.post(notification: .layoutChanged, argument: object)
                }
            }
        }
    }
    

    Add this extension and call it by passing in the view you would like to be focused. If you would like to change focus when navigating using a tabbar, you can call this from viewWillAppear. This code wont work in any init method without a the delay of 0.7 or more.

提交回复
热议问题