Mar*_*ijn 3 xcode constraints ios swift uipopoverpresentationcontroller
我尝试调用 popoverpresentation 视图控制器以在 ipad 上共享图像,但是当发生这种情况时,我收到错误“无法满足约束”。
事情是为了解决这个问题,我删除了所有约束,这样我就可以重新开始,但即使没有约束,我也会遇到同样的错误。
所以我的问题是。这是一个错误还是我必须为 popoverpresentation 视图控制器设置约束。
这是我的代码:
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)
}
Run Code Online (Sandbox Code Playgroud)
和控制台中的错误:
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.
Run Code Online (Sandbox Code Playgroud)
小智 6
我刚刚在我自己的项目中解决了同样的问题。
在 iPad 上显示 UIActivityViewController 时,您要么需要设置sourceViewANDsourceRect属性,要么需要设置该barButtonItem属性。
在我的项目中,我通过向shareButton点击时运行的块添加以下代码来解决该问题:
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.sourceRect = shareButton.frame
Run Code Online (Sandbox Code Playgroud)
该sourceRect是的CGRect的是,该UIActivityViewController“弹出”的。UIActivityViewController遗嘱上的箭头指向sourceRect
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |