带有主页按钮的 sfsafariviewcontroller 覆盖不起作用
sfsafariviewcontroller overlay with home button not working
我正在使用 SFSafariViewController
来显示网页,因为我需要 cookie 才能工作。我不想要 safari 搜索栏,所以我有一个覆盖层来隐藏它和一些按钮来执行一些任务。不过,我确实想要完成按钮的功能。由于我们有覆盖,完成按钮被隐藏并且不起作用,所以我尝试了下面的代码。但这也不起作用 -
self.presentViewController(sfController, animated: true) {
let bounds = UIScreen.mainScreen().bounds
// It can be any overlay. May be your logo image here inside an imageView.
let overlay = UIView(frame: CGRect(x: 0, y: 0, width: bounds.size.width, height: 65))
let completedBtn = UIButton()
let favBtn = UIButton()
let homeBtn = UIButton()
homeBtn.setTitle("Home",forState: .Normal)
homeBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
homeBtn.frame = CGRectMake(20, 25, 200, 35)
homeBtn.backgroundColor = UIColor(netHex: 0x6F9824)
homeBtn.addTarget(self, action: #selector(DetailsViewController.HomeBtnAction), forControlEvents: UIControlEvents.TouchUpInside)
completedBtn.setTitle("Completed",forState: .Normal)
completedBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
completedBtn.frame = CGRectMake((bounds.size.width - 210), 25, 200, 35)
completedBtn.backgroundColor = UIColor(netHex: 0x6F9824)
completedBtn.addTarget(self, action: #selector(DetailsViewController.CompletedAction), forControlEvents: UIControlEvents.TouchUpInside)
favBtn.setTitle("Favourite", forState: .Normal)
favBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
favBtn.frame = CGRectMake((bounds.size.width - 420), 25, 200, 35)
favBtn.backgroundColor = UIColor(netHex: 0x6F9824)
favBtn.addTarget(self, action: #selector(DetailsViewController.FavouriteAction), forControlEvents: UIControlEvents.TouchUpInside)
overlay.backgroundColor = UIColor(netHex: 0x435C16)
overlay.addSubview(favBtn)
overlay.addSubview(completedBtn)
overlay.addSubview(homeBtn)
sfController.view.addSubview(overlay)
}
On click of Home button i have this code -
func HomeBtnAction(){
let app = "MyApp://"
let appUrl = NSURL(string: app)
if UIApplication.sharedApplication().canOpenURL(appUrl!)
{
UIApplication.sharedApplication().openURL(appUrl!)
}
}
我的 plist 看起来像这样 -
<key>LSApplicationQueriesSchemes</key>
<array>
<string>MyApp</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Test.com.MyApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>MyApp</string>
</array>
</dict>
</array>
但是在点击主页按钮时,没有任何反应。它没有给出任何错误或警告信息。我也知道单击主页按钮时,我当前的代码会发出再次打开应用程序的警报,但我也不希望那样。我想要与 sfsafariviewcontroller 的 "done" 按钮完全相同的功能。我们可以做到这一点并且也有我的叠加层吗?
提前致谢!欢迎提出任何建议。
为什么不直接调用 presentViewcontroller 关闭函数。我用 swift 3 来测试这个源代码。它对我来说工作正常,我可以返回我的应用程序。
func HomeBtnAction(){
print("Button Pressed")
self.dismiss(animated: true, completion: nil)
}
我正在使用 SFSafariViewController
来显示网页,因为我需要 cookie 才能工作。我不想要 safari 搜索栏,所以我有一个覆盖层来隐藏它和一些按钮来执行一些任务。不过,我确实想要完成按钮的功能。由于我们有覆盖,完成按钮被隐藏并且不起作用,所以我尝试了下面的代码。但这也不起作用 -
self.presentViewController(sfController, animated: true) {
let bounds = UIScreen.mainScreen().bounds
// It can be any overlay. May be your logo image here inside an imageView.
let overlay = UIView(frame: CGRect(x: 0, y: 0, width: bounds.size.width, height: 65))
let completedBtn = UIButton()
let favBtn = UIButton()
let homeBtn = UIButton()
homeBtn.setTitle("Home",forState: .Normal)
homeBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
homeBtn.frame = CGRectMake(20, 25, 200, 35)
homeBtn.backgroundColor = UIColor(netHex: 0x6F9824)
homeBtn.addTarget(self, action: #selector(DetailsViewController.HomeBtnAction), forControlEvents: UIControlEvents.TouchUpInside)
completedBtn.setTitle("Completed",forState: .Normal)
completedBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
completedBtn.frame = CGRectMake((bounds.size.width - 210), 25, 200, 35)
completedBtn.backgroundColor = UIColor(netHex: 0x6F9824)
completedBtn.addTarget(self, action: #selector(DetailsViewController.CompletedAction), forControlEvents: UIControlEvents.TouchUpInside)
favBtn.setTitle("Favourite", forState: .Normal)
favBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
favBtn.frame = CGRectMake((bounds.size.width - 420), 25, 200, 35)
favBtn.backgroundColor = UIColor(netHex: 0x6F9824)
favBtn.addTarget(self, action: #selector(DetailsViewController.FavouriteAction), forControlEvents: UIControlEvents.TouchUpInside)
overlay.backgroundColor = UIColor(netHex: 0x435C16)
overlay.addSubview(favBtn)
overlay.addSubview(completedBtn)
overlay.addSubview(homeBtn)
sfController.view.addSubview(overlay)
}
On click of Home button i have this code -
func HomeBtnAction(){
let app = "MyApp://"
let appUrl = NSURL(string: app)
if UIApplication.sharedApplication().canOpenURL(appUrl!)
{
UIApplication.sharedApplication().openURL(appUrl!)
}
}
我的 plist 看起来像这样 -
<key>LSApplicationQueriesSchemes</key>
<array>
<string>MyApp</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Test.com.MyApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>MyApp</string>
</array>
</dict>
</array>
但是在点击主页按钮时,没有任何反应。它没有给出任何错误或警告信息。我也知道单击主页按钮时,我当前的代码会发出再次打开应用程序的警报,但我也不希望那样。我想要与 sfsafariviewcontroller 的 "done" 按钮完全相同的功能。我们可以做到这一点并且也有我的叠加层吗?
提前致谢!欢迎提出任何建议。
为什么不直接调用 presentViewcontroller 关闭函数。我用 swift 3 来测试这个源代码。它对我来说工作正常,我可以返回我的应用程序。
func HomeBtnAction(){
print("Button Pressed")
self.dismiss(animated: true, completion: nil)
}