如果我已经展示控制器,如何展示 Adyen 结账?
How to present Adyen checkout if i'm already presenting a controller?
我遇到了一个问题,我正在使用 tableview 作为侧边栏来显示应用程序中的某些控制器。尝试为付款预设 Adyen 结账时出现错误,提示我无法使用多显示,我的问题是,我该如何解决这个问题?
我想在按下结帐按钮后关闭侧边栏,或者按下侧边栏并显示其他控制器,但没有成功,或者我没有做对。
谢谢!
这是放置在 MainViewController 中的侧边菜单按钮
public func setSideMenuButton()
{
let button = UIButton()
button.frame = CGRect(x: self.view.frame.size.width - 65, y: self.view.frame.size.height - 160, width: 50, height: 50)
button.setImage(#imageLiteral(resourceName: "side_menu_button").withRenderingMode(.alwaysOriginal), for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.view.addSubview(button)
}
@objc func buttonAction(sender: UIButton!)
{
pauseEachExistingVideoPlayer()
guard let sideMenuViewController = storyboard?.instantiateViewController(withIdentifier: "SideMenuViewController") as? SideMenuViewController else { return }
sideMenuViewController.modalPresentationStyle = .overCurrentContext
sideMenuViewController.transitioningDelegate = self
present(sideMenuViewController, animated: true)
}
显示表格中的每个索引
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
switch indexPath.row {
case 0: present( UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "UserProfileVC") as UIViewController, animated: true, completion: nil)
case 1: present( UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SR_VideoLibrary") as UIViewController, animated: true, completion: nil)
case 2: present( UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SR_Livestream") as UIViewController, animated: true, completion: nil)
case 3: return
case 4: return
case 5: present( UIStoryboard(name: "VideoLibrary", bundle: nil).instantiateViewController(withIdentifier: "ProjectsListVC") as UIViewController, animated: true, completion: nil)
case 6: present( UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "GetPremiumVC") as UIViewController, animated: true, completion: nil)
default:
break
}
}
这就是我在外部点击时关闭容器视图并关闭侧边栏的方式
class SideMenuViewController: UIViewController, UITableViewDelegate
{
@IBOutlet weak var modalView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
if let view = modalView
{
addTapGesture(target: view, action: #selector(dismissController))
}
}
@objc private func dismissController()
{
dismiss(animated: true, completion: nil)
}
}
extension SideMenuViewController {
func addTapGesture(target: UIView, action: Selector, numberOfTaps: Int = 1) {
let tap = UITapGestureRecognizer(target: self, action: action)
tap.numberOfTapsRequired = numberOfTaps
target.isUserInteractionEnabled = true
target.addGestureRecognizer(tap)
}
}
This is the side menu storyboard
恐怕这是 UIKit 的一个限制,一个 View Controller 只能呈现另一个 ViewController。
所以我怎么看,你有两个选择,要么首先关闭已经呈现的 SideMenuViewController
,要么让 SideMenuViewController
呈现 Adyen 视图控制器。
如果您使用的是 Adyen checkout SDK 3.5.0,则在 UIViewController 的每个实例中都添加了一个助手 属性 来获取最上面显示的视图控制器,请使用此 [= MainViewController
的 27=] - 或任何其他对呈现 adyen 结帐视图控制器有意义的视图控制器 - 在其上呈现另一个视图控制器。
presenterViewController.adyen.topPresenter.present(secondPresentedVC, animated: true)
如果您使用的 SDK 版本中没有此 adyen
帮助程序,您可以实现 UIViewController 的扩展,如下所示:
extension UIViewController {
var topPresenter: UIViewController {
var topController: UIViewController = self
while let presenter = topController.presentedViewController {
topController = presenter
}
return topController
}
}
希望对您有所帮助!
我遇到了一个问题,我正在使用 tableview 作为侧边栏来显示应用程序中的某些控制器。尝试为付款预设 Adyen 结账时出现错误,提示我无法使用多显示,我的问题是,我该如何解决这个问题?
我想在按下结帐按钮后关闭侧边栏,或者按下侧边栏并显示其他控制器,但没有成功,或者我没有做对。
谢谢!
这是放置在 MainViewController 中的侧边菜单按钮
public func setSideMenuButton()
{
let button = UIButton()
button.frame = CGRect(x: self.view.frame.size.width - 65, y: self.view.frame.size.height - 160, width: 50, height: 50)
button.setImage(#imageLiteral(resourceName: "side_menu_button").withRenderingMode(.alwaysOriginal), for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.view.addSubview(button)
}
@objc func buttonAction(sender: UIButton!)
{
pauseEachExistingVideoPlayer()
guard let sideMenuViewController = storyboard?.instantiateViewController(withIdentifier: "SideMenuViewController") as? SideMenuViewController else { return }
sideMenuViewController.modalPresentationStyle = .overCurrentContext
sideMenuViewController.transitioningDelegate = self
present(sideMenuViewController, animated: true)
}
显示表格中的每个索引
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
switch indexPath.row {
case 0: present( UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "UserProfileVC") as UIViewController, animated: true, completion: nil)
case 1: present( UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SR_VideoLibrary") as UIViewController, animated: true, completion: nil)
case 2: present( UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SR_Livestream") as UIViewController, animated: true, completion: nil)
case 3: return
case 4: return
case 5: present( UIStoryboard(name: "VideoLibrary", bundle: nil).instantiateViewController(withIdentifier: "ProjectsListVC") as UIViewController, animated: true, completion: nil)
case 6: present( UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "GetPremiumVC") as UIViewController, animated: true, completion: nil)
default:
break
}
}
这就是我在外部点击时关闭容器视图并关闭侧边栏的方式
class SideMenuViewController: UIViewController, UITableViewDelegate
{
@IBOutlet weak var modalView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
if let view = modalView
{
addTapGesture(target: view, action: #selector(dismissController))
}
}
@objc private func dismissController()
{
dismiss(animated: true, completion: nil)
}
}
extension SideMenuViewController {
func addTapGesture(target: UIView, action: Selector, numberOfTaps: Int = 1) {
let tap = UITapGestureRecognizer(target: self, action: action)
tap.numberOfTapsRequired = numberOfTaps
target.isUserInteractionEnabled = true
target.addGestureRecognizer(tap)
}
}
This is the side menu storyboard
恐怕这是 UIKit 的一个限制,一个 View Controller 只能呈现另一个 ViewController。
所以我怎么看,你有两个选择,要么首先关闭已经呈现的 SideMenuViewController
,要么让 SideMenuViewController
呈现 Adyen 视图控制器。
如果您使用的是 Adyen checkout SDK 3.5.0,则在 UIViewController 的每个实例中都添加了一个助手 属性 来获取最上面显示的视图控制器,请使用此 [= MainViewController
的 27=] - 或任何其他对呈现 adyen 结帐视图控制器有意义的视图控制器 - 在其上呈现另一个视图控制器。
presenterViewController.adyen.topPresenter.present(secondPresentedVC, animated: true)
如果您使用的 SDK 版本中没有此 adyen
帮助程序,您可以实现 UIViewController 的扩展,如下所示:
extension UIViewController {
var topPresenter: UIViewController {
var topController: UIViewController = self
while let presenter = topController.presentedViewController {
topController = presenter
}
return topController
}
}
希望对您有所帮助!