共享文本iPhone和iPad

问题描述 投票:0回答:1

我需要在iPhone和iPad上共享文本。我的代码在iPhone上可以工作,但在iPad上不能工作。

我使用了一个静态函数来调用 trailingSwipeActionsConfigurationForRowAt 我的 tableView:

static func dialogCompartir(titulo: String, descripcion: String, view: UIViewController, url: String) -> Void {
    // Set the link to share.
    if let link = NSURL(string: url) {
        let objectsToShare = [descripcion,link] as [Any]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

        if UIDevice.current.userInterfaceIdiom == .pad {
            print("ipad")
            view.present(activityVC, animated: true, completion: nil)
            if let popOver = activityVC.popoverPresentationController {
                popOver.sourceView =  view.view
              //popOver.sourceRect =
              //popOver.barButtonItem
            }
        } else if UIDevice.current.userInterfaceIdiom == .phone {
            print("iphone")
            view.present(activityVC, animated: true, completion: nil)
        }
    }
}

iPad错误。

[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:0x60000188f890 LPLinkView:0x7fdd2a70d200.leading == UILayoutGuide:0x6000002ac0e0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600001889d10 H:[LPLinkView:0x7fdd2a70d200]-(59)-|   (active, names: '|':_UIActivityContentTitleView:0x7fdd2a70cde0 )>",
    "<NSLayoutConstraint:0x6000018e50e0 H:|-(0)-[_UIActivityContentTitleView:0x7fdd2a70cde0]   (active, names: '|':_UINavigationBarContentView:0x7fdd27dae070 )>",
    "<NSLayoutConstraint:0x6000018e5590 _UIActivityContentTitleView:0x7fdd2a70cde0.trailing == _UINavigationBarContentView:0x7fdd27dae070.trailing   (active)>",
    "<NSLayoutConstraint:0x600001893520 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7fdd27dae070.width == 0   (active)>",
    "<NSLayoutConstraint:0x60000188f840 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x6000002ac0e0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIActivityContentTitleView:0x7fdd2a70cde0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60000188f890 LPLinkView:0x7fdd2a70d200.leading == UILayoutGuide:0x6000002ac0e0'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.

如何解决Xcode 11、iOS 13在iPad上分享文字的问题?

我的 TableViewController 没有约束警告。

ios swift xcode ipad
1个回答
0
投票

为popOver提供源矩形

popOver.sourceRect = CGRect(x: 0, y: 0, width: 100, height: 100) // You can use your sender rect here

iOS 13.2中的默认值是CGRectNull。在iOS 13.2之前,默认值是CGRectZero。


0
投票

我在iPad、xcode11、ios13中都能用。

        if UIDevice.current.userInterfaceIdiom == .phone{
            print("===== iPhone")
            view.present(activityVC, animated: true, completion: nil)

        }else if UIDevice.current.userInterfaceIdiom == .pad{
            print("===== iPad")
            view.present(activityVC, animated: true, completion: nil)

            if let popOver = activityVC.popoverPresentationController {
                popOver.sourceView = view.tableView
                popOver.sourceRect = view.tableView.rectForRow(at: indexPath)
                popOver.permittedArrowDirections = UIPopoverArrowDirection.any

            }

        }

问候

© www.soinside.com 2019 - 2024. All rights reserved.