我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 的“完成”按钮完全相同的功能。我们能做到这一点并且也有我的覆盖吗?
提前致谢!欢迎提出任何建议。