gpt4 book ai didi

ios - UIAccessibility 焦点与 UITabBarController

转载 作者:行者123 更新时间:2023-12-01 22:09:36 29 4
gpt4 key购买 nike

如何将 UIAccessibility 焦点设置在 UITabBarController 的选定选项卡的内容上?它一直关注选定的 UITabBarItem

我尝试在 UITabBarControllerDelegate 中设置焦点:

    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {

if let destination = (viewController as? UINavigationController)?.viewControllers.first {
UIAccessibility.post(notification: .screenChanged, argument: destination)
} else {
UIAccessibility.post(notification: .screenChanged, argument: viewController)
}
}

我还尝试在选定的 UIViewController 中设置焦点:

    override func viewDidAppear(_ animated: Bool) {

super.viewDidAppear(animated)

UIAccessibility.post(notification: .screenChanged, argument: accessibilityElements?.first)
}

不幸的是,可访问性焦点没有改变。我不确定这是 iOS 13 问题还是一般标签栏问题,因为即使是 Apple 自己的 AppStore 应用程序在选择标签页时也不会改变辅助功能焦点。

最佳答案

我不确定它有多大帮助,但我设法通过延迟发布通知找到了解决方法。

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if UIAccessibility.isVoiceOverRunning {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(1.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {
UIAccessibility.post(notification: .layoutChanged, argument: self.whateverElementYouNeed)
})
}
}

关于ios - UIAccessibility 焦点与 UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58234254/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com