如何将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的问题还是一般的选项卡栏问题,因为即使是苹果自己的AppStore应用程序在选择选项卡时也不会改变辅助功能的焦点。
发布于 2020-02-21 21:03:23
我不确定它有多大帮助,但我已经设法找到了一个解决方法,通过发布延迟通知。
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)
})
}
}https://stackoverflow.com/questions/58234254
复制相似问题