我有一个点击手势操作,可以打开 Apple App Store 产品显示:
let storeProductViewController = SKStoreProductViewController()
@objc func adTap(sender: UITapGestureRecognizer? = nil) -> Void {
if adAppID.isEmpty {return}
let paramDict = [SKStoreProductParameterITunesItemIdentifier: adAppID]
storeProductViewController.loadProduct(withParameters: paramDict, completionBlock: { (status: Bool, error: Error?) -> Void in
if status {
// self.storeProductViewController.edgesForExtendedLayout = []
// self.storeProductViewController.additionalSafeAreaInsets = UIEdgeInsets(top: 40, left: 0, bottom: 0, right: 0)
// self.storeProductViewController.modalPresentationCapturesStatusBarAppearance = false
self.present(self.storeProductViewController, animated: true, completion: nil)
}
else {
if let error = error {
print("Error: \(error.localizedDescription)")
}
}})
}
func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
viewController.presentingViewController?.dismiss(animated: true, completion: nil)
}
第一次用户点击,一切都很好。点击系统提供的标准“完成”按钮,模式商店 View 将弹出,用户将返回到应用程序中的原始 View 。
如果用户再次点击手势操作 View ,则会显示商店产品 View ,但“完成”按钮向上移动,现在位于“安全”区域上方的时间显示下方。它部分地被时间遮盖,并且对敲击也不敏感。死锁 - 无法返回我的应用程序。
我没有明确创建 SKStore 使用的导航 Controller ,我认为我无法控制它。
我已经尝试了代码中注释掉的三种方法来按下呈现的商店 View 及其附件完成按钮。这三个都不起作用。
我在这里做错了什么,或者如何解决?
附录:更多失败的方法:实例化商店 View 后,我尝试直接设置其 View 和图层框架,并且还插入了父 View 的安全区域和边距 - 对“完成”按钮没有任何影响。
进一步深入兔子洞:比较第一次和第二次调用 StoreProductView Present 的屏幕截图(注意,两种不同的产品,但这并不重要,我都尝试过!),我们可以看到垂直偏移到两个 View 的商店应用程序图标和名称相同。只是“完成”按钮从正常位置移到了使用区域的时间/位置下方。
最佳答案
进一步调查显示 StoreProductViewController 有一个正在更改的 view.frame.origin.y (出于未知原因,我没有故意更改它):
Native rects, first run (No forced changes)
Self.View.frame: (0.0, 0.0, 414.0, 896.0)
Self.View.bounds: (0.0, 0.0, 414.0, 896.0)
Store.View.frame: (0.0, 0.0, 0.0, 0.0)
Store.View.bounds: (0.0, 0.0, 0.0, 0.0)
Native rects, second run
Self.View.frame: (0.0, 0.0, 414.0, 896.0)
Self.View.bounds: (0.0, 0.0, 414.0, 896.0)
Store.View.frame: (0.0, 896.0, 414.0, 896.0)
Store.View.bounds: (0.0, 0.0, 414.0, 896.0)
所以,我只是通过将此行放在presentVC之前来强制它恢复到原始值
self.self.storeProductViewController.frame.origin.y = 0.0
然后按钮停留在它所属的位置,调试跟踪是:
Force store origin.y to zero first run
Self.View.frame: (0.0, 0.0, 414.0, 896.0)
Self.View.bounds: (0.0, 0.0, 414.0, 896.0)
Store.View.frame: (0.0, 0.0, 0.0, 0.0)
Store.View.bounds: (0.0, 0.0, 0.0, 0.0)
Force store origin.y to zero, second run
Self.View.frame: (0.0, 0.0, 414.0, 896.0)
Self.View.bounds: (0.0, 0.0, 414.0, 896.0)
Store.View.frame: (0.0, 0.0, 414.0, 896.0)
Store.View.bounds: (0.0, 0.0, 414.0, 896.0)
关于ios - 呈现 App Store 产品 View Controller 变得不可逆转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56050439/