我SFSafariViewController
需要显示Cookie才能显示网页。我不需要野生动物园搜索栏,所以我有一个隐藏它的覆盖物和一些执行某些任务的按钮。我确实想要完成按钮的功能。由于已经覆盖,完成按钮被隐藏并且不起作用,因此我在下面的代码中进行了尝试。但这效果不佳-
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!)
}
}
我的清单看起来像这样-
<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的“完成”按钮完全相同的功能。我们可以做那个工作,也可以覆盖我吗?
提前致谢!并欢迎任何建议。
您为什么不只调用presentViewcontroller dismiss函数。我使用swift 3测试了此源代码。它对我来说正常工作,我可以返回到我的应用程序。
func HomeBtnAction(){
print("Button Pressed")
self.dismiss(animated: true, completion: nil)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句