为何同一链接在SFSafariViewController中‘朗读页面’按钮禁用,原生Safari却可用?
解决SFSafariViewController“朗读页面”按钮禁用的问题
你遇到的问题根源在于用导航栈推送(push)SFSafariViewController的呈现方式,这种方式会限制Safari的原生功能,包括“朗读页面”按钮的启用。原生Safari是独立模态界面,应用中必须用模态呈现(present)才能匹配其功能逻辑。
修改后的代码:
@IBAction func showSafari(_ sender: UIButton) { guard let url = URL(string: "https://dotat.at/@/2024-01-29-four-point-egg.html") else { return } var safariVC : SFSafariViewController if #available(iOS 11.0, *) { let config = SFSafariViewController.Configuration() config.barCollapsingEnabled = true safariVC = SFSafariViewController(url: url, configuration: config) safariVC.dismissButtonStyle = .close } else { safariVC = SFSafariViewController(url: url) } // 替换push为模态present present(safariVC, animated: true) }
补充说明:
- SFSafariViewController的设计定位是独立的模态浏览器组件,推送至导航栈会破坏其原生功能的完整性,iOS 17.x版本对这一限制的管控更严格。
- 改成模态呈现后,“朗读页面”按钮会和原生Safari一样正常启用,其他Safari原生功能也能正常使用。
应用内原效果:
原生Safari效果:
内容的提问来源于stack exchange,提问作者sudoExclamationExclamation
相关产品推荐
相关产品推荐

