Общий текст iPhone и iPad - PullRequest
       43

Общий текст iPhone и iPad

0 голосов
/ 09 мая 2020

Мне нужно отправить текст на iPhone и iPad. Мой код работает для iPhone, но не работает для iPad.

Я использую функцию stati c для вызова из 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.

Как я могу решить эту проблему обмена текстом на iPad для Xcode 11, iOS 13?

Мой TableViewController не имеет предупреждений об ограничениях.

Ответы [ 2 ]

0 голосов
/ 11 мая 2020

Это сработало для меня в 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

            }

        }

Приветствую

0 голосов
/ 09 мая 2020

Предоставляет исходный прямоугольник для 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.

...