gpt4 book ai didi

ios - 如何正确地将 UIButton 放置在已加载的 SFSafariViewController 之上?

转载 作者:行者123 更新时间:2023-11-30 12:13:30 25 4
gpt4 key购买 nike

我读过很多关于 SFSafariViewController 的文章,我相信它在 iOS 应用程序中提供了出色的功能。但是,当我加载 SFSafariViewController 时,我故意隐藏导航栏,因为我希望左上角有一个自定义固定按钮来关闭 View Controller 。

    override func viewDidAppear(_ animated: Bool) {
let safariViewController = PSSafariViewController(url: URL(string: blogUrl)!, entersReaderIfAvailable: true)
present(safariViewController, animated: false) {
var frame = safariViewController.view.frame
let OffsetY: CGFloat = 44
frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y - OffsetY)
frame.size = CGSize(width: frame.width, height: frame.height + OffsetY)
safariViewController.view.frame = frame
let btn: UIButton = UIButton(frame: CGRect(x: 100, y: 400, width: 100, height: 50))
btn.backgroundColor = UIColor.green
btn.setTitle("Click Me", for: .normal)
btn.addTarget(self, action: #selector(PSBlogViewController.buttonAction), for: UIControlEvents.touchUpInside)
btn.tag = 1 // change tag property
btn.isOpaque = true
safariViewController.view.addSubview(btn)
safariViewController.view.bringSubview(toFront: btn)
print(btn.description)
}
}

如您所见,我更改了框架,使顶部的栏不可见。该代码运行良好。但是当我尝试添加 UIButton 时,它会短暂出现,然后在我运行应用程序时被覆盖。这是一个使用 SFSafariViewController 的简单博客阅读器应用程序。也许苹果不希望开发人员到处乱搞这个,但是任何使按钮保持可见的解决方案或变通方法都将受到高度赞赏!

这是有关按钮的信息:0x7f950b618db0;帧=(100 400;100 50);标签=1;层= CALayer:0x60000023ab60

最佳答案

为什么不使用其他 WebView 类之一来获得您想要的额外功能?

5.1.1 (iv) SafariViewContoller must be used to visibly present information to users; the controller may not be hidden or obscured by other views or layers. Additionally, an app may not use SafariViewController to track users without their knowledge and consent.

关于ios - 如何正确地将 UIButton 放置在已加载的 SFSafariViewController 之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45725732/

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