我有一个带有导航栏的应用程序,该导航栏带有一个共享按钮,用于捕获视图并与Facebook,Twitter,Imessages等共享。在底部,我还有一个UIStackView,它允许我在视图之间来回滑动。
问题是当我使用此代码时:
@objc func handleShare() {
print("sharing image")
UIGraphicsBeginImageContext(view.frame.size)
view.layer.render(in: UIGraphicsGetCurrentContext()!)
guard let image = UIGraphicsGetImageFromCurrentImageContext()
else {return}
let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
activityViewController.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(activityViewController, animated: true, completion: nil)
}
它还捕获了我的UIStackView(视图底部的上一个和下一个按钮)。
有什么办法可以指定要捕获的视图的哪一部分?
所有代码都是以编程方式完成的,没有情节提要编码。
答案 0 :(得分:0)
传递要捕获的UIView。使stackView不在传递给函数的视图中。
@objc func handleShare(yourView: UIView) {
print("sharing image")
UIGraphicsBeginImageContext(yourView.frame.size)
view.layer.render(in: UIGraphicsGetCurrentContext()!)
guard let image = UIGraphicsGetImageFromCurrentImageContext()
else {return}
let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
activityViewController.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(activityViewController, animated: true, completion: nil)
}