gpt4 book ai didi

ios - Popoverpresentation View Controller 和约束问题

转载 作者:行者123 更新时间:2023-11-29 05:13:03 28 4
gpt4 key购买 nike

我尝试调用 popoverpresentation View Controller 以便在 ipad 上共享图像,但当发生这种情况时,我收到错误“无法满足约束”。

问题是为了解决这个问题,我删除了所有约束,这样我就可以重新开始,但即使没有约束,我也会遇到同样的错误。

所以我的问题是。这是一个错误还是我必须为 popoverpresentation View Controller 设置约束。

这是我的代码:

print("Current device is an iPad")
print("Current device is \(UIDevice.current)")

if let imageCheck = image {
let imageToShare = [imageCheck]
let activityVC = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)

activityVC.popoverPresentationController?.sourceView = super.view
self.present(activityVC, animated: true, completion: nil)
}

控制台中的错误:

Current device is an iPad
Current device is <UIDevice: 0x280c8d260>
2019-12-26 20:31:22.662290+0100 Petfie[2184:756367] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x282f83c00 LPLinkView:0x15be4c7a0.leading == UILayoutGuide:0x2835a8c40'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x282f83840 H:[LPLinkView:0x15be4c7a0]-(59)-| (active, names: '|':_UIActivityContentTitleView:0x15be47560 )>",
"<NSLayoutConstraint:0x282f85d10 H:|-(0)-[_UIActivityContentTitleView:0x15be47560] (active, names: '|':_UINavigationBarContentView:0x15be57940 )>",
"<NSLayoutConstraint:0x282f85d60 _UIActivityContentTitleView:0x15be47560.trailing == _UINavigationBarContentView:0x15be57940.trailing (active)>",
"<NSLayoutConstraint:0x282f9eb20 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x15be57940.width == 0 (active)>",
"<NSLayoutConstraint:0x282f83b10 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x2835a8c40'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIActivityContentTitleView:0x15be47560 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x282f83c00 LPLinkView:0x15be4c7a0.leading == UILayoutGuide:0x2835a8c40'UIViewLayoutMarginsGuide'.leading (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

最佳答案

我刚刚在自己的项目中解决了同样的问题。

在 iPad 上显示 UIActivityViewController 时,您需要设置 sourceViewsourceRect 属性,或者需要设置 barButtonItem 属性。

在我的项目中,我通过将以下代码添加到点击 shareButton 时运行的 block 来解决该问题:

activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.sourceRect = shareButton.frame

sourceRectUIActivityViewController“弹出”的 CGRect。 UIActivityViewController 上的箭头将指向 sourceRect

关于ios - Popoverpresentation View Controller 和约束问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59492765/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com