为什么UIActivityViewController会在iPad上导致自动布局约束错误?

时间:2020-04-23 18:21:35

标签: autolayout uiactivityviewcontroller

我正在向我的应用程序添加新功能,该功能允许用户通过UIActivityViewController共享表共享PDF。这在iPhone上有效,但会产生约束错误。但是,在iPad上,共享表根本没有出现,并且存在约束错误。

我的代码:

 @IBAction func shareAction(_ sender: UIBarButtonItem) {

    print ("let's share")

    let textToShare = "Select sharing option or save to Files app"

    if let pdfData = self.pdfView.document?.dataRepresentation() {

        let objectsToShare = [textToShare, pdfData] as [Any]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities:nil)

        //New Excluded Activities Code
        activityVC.excludedActivityTypes = [UIActivity.ActivityType.addToReadingList, UIActivity.ActivityType.postToFacebook,UIActivity.ActivityType.postToTwitter]
        //
        print ("let's present vc")

        DispatchQueue.main.async {

        activityVC.popoverPresentationController?.sourceView = self.view

        self.present(activityVC, animated: true, completion: nil)

                }

            }

        }

报告的错误:

      (
      "<NSLayoutConstraint:0x280bfb7f0    LPLinkView:0x11242d950.leading == UILayoutGuide:0x2811bce00'UIViewLayoutMarginsGuide'.leading   (active)>",
     "<NSLayoutConstraint:0x280bfaf30 H:[LPLinkView:0x11242d950]-(59)-|   (active, names: '|':_UIActivityContentTitleView:0x100bdc0b0 )>",
     "<NSLayoutConstraint:0x280b95040 H:|-(0)-[_UIActivityContentTitleView:0x100bdc0b0]   (active, names: '|':_UINavigationBarContentView:0x100db4290 )>",
     "<NSLayoutConstraint:0x280b96710  _UIActivityContentTitleView:0x100bdc0b0.trailing == _UINavigationBarContentView:0x100db4290.trailing   (active)>",
     "<NSLayoutConstraint:0x280bd2c60 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x100db4290.width == 6   (active)>",
     "<NSLayoutConstraint:0x280bfb8e0 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x2811bce00'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIActivityContentTitleView:0x100bdc0b0 )>"
     )

    Will attempt to recover by breaking constraint 
   <NSLayoutConstraint:0x280bfb7f0 LPLinkView:0x11242d950.leading   == UILayoutGuide:0x2811bce00'UIViewLayoutMarginsGuide'.leading     (active)>

我所知道的:

我知道存在一个约束错误,并且我的问题与五个月前在这里描述的问题基本相同:

Why is UIActivityViewController displaying auto constraint errors in console

到目前为止,我为解决问题所做的尝试:

•我确实尝试按照链接底部的建议使用Dispatch.main.async进行放置,但是并不能解决我的问题。

•我还尝试了从DetailViewController中删除所有约束,但这也不能解决问题。约束错误仍然存​​在。没有约束,怎么会有约束错误?

我的代码是否有问题,或者这是与Apple相同的未解决错误?如果是后者,是否有解决方法?

谢谢

Eli

0 个答案:

没有答案